AllenAdministrator
(KiX Supporter)
2010-12-06 06:01 PM
Kixgolf - Bowling Calculator - Public Round

Please post your code...

maciep
(Korg Regular)
2010-12-06 06:06 PM
Re: Kixgolf - Bowling Calculator - Public Round

Here is my 156 code

 Code:
function a($s)
	dim $,$t,$y,$z
	while $s
		$ = left($s,1)
		$s = right($s,~)
		if $>#
			$a = (1+$y+$z)*(10*($=x)+$+($='/')*(10-$t)) + $a
			$z = ($t=x)*$y
			$y = ($=x | $='/')*($s<#)
			$t = $
		;endif
	;loop
endfunction


And here is a brief explanation of it

 Quote:

Since we only care about the total score, we don't need to calculate each frame and then add those together. Instead we can keep a running total following the following idea:

Depending on the previous scores, we will add the current score
-once, if no spares or strikes carry over
-twice, if only one spare or strike carries over
-3 times, if a strike and either another strike or spare carries over

So we loop through each character in the string of scores passed in. If the character is not a space, i.e. $># then process...

First, we calculate the total for this score

$a = (1+$z+$y)*(10*($=x) + $ + ($='/')*(10-$t)) + $a

(1+$z+$y)
This is the multiplier. It will always be at least 1

10*($=x)
If it's a strike, then the score is 10.

$
if $ is a number, then just add the number itself. If it's not a number, then it will evaluate to 0

($='/')*(10-$t)
If it's a spare, then the score is 10. BUT the spare means the current score PLUS the last one is 10, so we need to subtract
the previous score from 10

Now multiply the multiplier times the score, add to our current total and move on.

Next, we figure out the multiplier for the next round

$z= ($t=x)*$y
If the previous score was a strike and it we counted it this round, we'll count it next round


$y = ($=x | $='/')*($s<#)
if this score was a strike or a spare, and not in the 10th frame, then count it. If it is not in the 10th frame
then $x will begin with a space and therefore be less than #.

Store the current score in $y which will be needed if the next score is a spare, as well as for the next $z assignment.

$t=$
Set $t to the current score which we may need in the next round


AllenAdministrator
(KiX Supporter)
2010-12-06 06:13 PM
Re: Kixgolf - Bowling Calculator - Public Round

Here is Jochen's 155
 Code:
function a($x)
    dim $v, $b, $
    while $x
        $ = left($x,1)
        $x = right($x,~)
        if $>!
            $v = ($=X)*10 + $ + ($="/")*(10-$v)
            $a = $a + ($b-($b>1)+1)*$v
            $b = ($b>1) + (2*($=X)^$="/")*($x<!)
endfunction



maciep
(Korg Regular)
2010-12-06 06:27 PM
Re: Kixgolf - Bowling Calculator - Public Round

so yeah....almost the same code \:\)

ShaneEP
(MM club member)
2010-12-06 06:42 PM
Re: Kixgolf - Bowling Calculator - Public Round

Here's my beast of a code. I went about it a bit differently (resulting in more strokes). I parsed the string into two matching arrays, one with the actual characters and one with the values of those characters. This allowed to cross reference and still be able to tell if a value came from a strike or spare. Nothing to complicated. Could have declared a multi dimen array instead of two and saved some strokes probably, but I kind of ran out of time to work on it. This week is finals week in school, so I probably shouldnt have worked on it at all...but priorities, ya know.
 Code:
function a($z)
   Dim $o,$j,$,$l,$v[22],$d[22]
   $o=split($z," ")
   $j=join($o,"")
   for $=1 to 22
      $l=substr($j,$,1)
      $d[$]=$l
      $v[$]=iif($l=X,10,iif($l="/",10-$v[$-1],cint($l)))
      $a=$a+$v[$]
   next
   for $=1 to len($j)-len($o[9])
      if $d[$]="/"
         $a=$a+$v[$+1]
      else
         if $d[$]=X
            $a=$a+$v[$+1]+$v[$+2]
;         endif
;      endif
;   next
endfunction


ShaneEP
(MM club member)
2010-12-06 07:36 PM
Re: Kixgolf - Bowling Calculator - Public Round

Man I wish I had the math logic down like you guys. I can barely wrap my head around how to do it, even after seeing your code and explanations.

LonkeroAdministrator
(KiX Master Guru)
2010-12-06 07:54 PM
Re: Kixgolf - Bowling Calculator - Public Round

my 181:
 Code:
function a($i)
dim $1,$
  $=join(split($i),'')
  $1=left($,1)
  $a=substr($,3,1)
  $=substr($,2,1)
  if $
  $a=($a='/')*(10-$)+$+iif($1=x | $='/',10*(1+(x=$a)+($=x))+$a,$1)+a(right($i,(x=$1)-3))
endfunction


LonkeroAdministrator
(KiX Master Guru)
2010-12-06 09:44 PM
Re: Kixgolf - Bowling Calculator - Public Round

153 from jochen's:
 Code:
function a($x)
    dim $v, $b, $
    while $x
        $ = left($x,1)
        $x = right($x,~)
        if $>!
            $v = ($=X)*10 + $ + ($="/")*(10-$v)

            $a = $a +($b+($b<2))*$v
            $b = ($b>1) + (2*($=X)^$="/")*($x<!)
endfunction


JochenAdministrator
(KiX Supporter)
2010-12-06 09:53 PM
Re: Kixgolf - Bowling Calculator - Public Round

Nice one Jooel,
why haven't I thought about that before \:o


BradV
(Seasoned Scripter)
2010-12-06 10:41 PM
Re: Kixgolf - Bowling Calculator - Public Round

 Code:
function a($)
   dim $s[9], $c, $e, $k, $l, $m, $i
   $s = Split($," ")
   for $i = 9 to 0 step -1
      $k = Substr($s[$i],1,1)
      $l = Substr($s[$i],2,1)
	   if $i = 9
	      if $k = "X"
		      $m = Substr($s[$i],3,1)
				if $m = "/"
				   $a = 20
				else
		         $a = 10 + d($l) + d($m)
				endif
			else
			   if $l = "/"
		         $m = Substr($s[$i],3,1)
		         $a = 10 + d($m)
				else
				   $a = 0 + d($k) + d($l)
				endif
         endif
	      $c = $k
		   $e = $l
      else
	      if $k = "X"
		      $a = $a + d($k) + d($c) + d($e)
            $e = $c
		      $c = $k
		   else
		      if $l = "/"
			      $a = $a + d($l) + d($c)
	            $c = $k
		         $e = 10 - $k
			   else
			      $a = $a + d($k) + d($l)
	            $c = $k
		         $e = $l
			   endif
		   endif
		endif
	next
endfunction
;!
function d($)
   $d = iif(InStr($, "X") or InStr($, "/"),10,iif(InStr($, "-"),0,$))
endfunction


I obviously over complicated it. \:\(


ShaneEP
(MM club member)
2010-12-06 10:49 PM
Re: Kixgolf - Bowling Calculator - Public Round

Same here Brad. I started with something very similar to yours. Had to rewrite it about 5 times just to get it down to what I ended up with.

LonkeroAdministrator
(KiX Master Guru)
2010-12-06 11:22 PM
Re: Kixgolf - Bowling Calculator - Public Round

J, dunno but looked weird and kept bugging me for total of 2 mins until I decided something has to give ;\)
and indeed there was extra strokes \:\)


JochenAdministrator
(KiX Supporter)
2010-12-07 08:00 AM
Re: Kixgolf - Bowling Calculator - Public Round

Maybe I haven't had this constellation long enough to bug my eye.. It was the improvement from 163 to 157.

LonkeroAdministrator
(KiX Master Guru)
2010-12-07 08:46 AM
Re: Kixgolf - Bowling Calculator - Public Round

oh.
doesn't really hurt you eyes when you think "this baby is my leader" \:\)


JochenAdministrator
(KiX Supporter)
2010-12-07 09:53 AM
Re: Kixgolf - Bowling Calculator - Public Round

ok, now to squeeze one or more out of my baby.. that'll be hard.

LonkeroAdministrator
(KiX Master Guru)
2010-12-07 10:55 AM
Re: Kixgolf - Bowling Calculator - Public Round

don't have time to look at it now but there should be more to be shaved in there.
still looks too "messy"


LonkeroAdministrator
(KiX Master Guru)
2010-12-07 03:09 PM
Re: Kixgolf - Bowling Calculator - Public Round

clever code you guys managed to put out. nice.

BradV
(Seasoned Scripter)
2010-12-07 03:23 PM
Re: Kixgolf - Bowling Calculator - Public Round

I was working on another version that first converted the "X/-" to numbers and then did a long immediate if to get the results. I had half successful, but didn't have time to finish. I'll have to look at your scripts this afternoon when I get home to try and understand. \:\)

AllenAdministrator
(KiX Supporter)
2010-12-07 10:13 PM
Re: Kixgolf - Bowling Calculator - Public Round

Someone mind explaining this line?

 Code:
2*($=X)^$="/"


LonkeroAdministrator
(KiX Master Guru)
2010-12-07 11:05 PM
Re: Kixgolf - Bowling Calculator - Public Round

basicly the same as 2*($=x)+($='/')

JochenAdministrator
(KiX Supporter)
2010-12-08 11:19 AM
Re: Kixgolf - Bowling Calculator - Public Round

... and completely unnecessary

Kixgolf Score = 151

 Code:
function a($x)
    dim $v, $b, $
    while $x
        $ = left($x,1)
        $x = right($x,~)
        if $>!
            $v = ($=X)*10 + $ + ($="/")*(10-$v)
            $a = $a + ($b+($b<2))*$v
            $b = ($b>1) + instr("/X",$)*($x<!)
endfunction


LonkeroAdministrator
(KiX Master Guru)
2010-12-08 12:40 PM
Re: Kixgolf - Bowling Calculator - Public Round

wohoo!
I tried something similar but you got it working! way to go!!!!


LonkeroAdministrator
(KiX Master Guru)
2010-12-08 09:45 PM
Re: Kixgolf - Bowling Calculator - Public Round

well...
how about 149?
 Code:
function a($x)
    dim $v, $b, $
    while $x
        $ = left($x,1)
        $x = right($x,~)
        if $>!
            $v = ($=X)*10 + $ + ($="/")*(10-$v)
            $a = $a + ($b+($b<2))*$v
            $b = instr("/X",$)*($x<!) + $b/2
endfunction


JochenAdministrator
(KiX Supporter)
2010-12-09 08:08 AM
Re: Kixgolf - Bowling Calculator - Public Round

hehe, yeah,
quite obvious


JochenAdministrator
(KiX Supporter)
2010-12-09 08:24 PM
Re: Kixgolf - Bowling Calculator - Public Round

 Originally Posted By: Allen
Please post your code...


When does it end? Countdown clock?


AllenAdministrator
(KiX Supporter)
2010-12-09 09:28 PM
Re: Kixgolf - Bowling Calculator - Public Round

Ey Ey Capitan...



JochenAdministrator
(KiX Supporter)
2010-12-09 09:36 PM
Re: Kixgolf - Bowling Calculator - Public Round

Brain hurts big time ...

AllenAdministrator
(KiX Supporter)
2010-12-10 12:41 AM
Re: Kixgolf - Bowling Calculator - Public Round

Curious... anyone try to do it with 30 pins as a max per frame and subtract accordingly?

JochenAdministrator
(KiX Supporter)
2010-12-10 07:33 AM
Re: Kixgolf - Bowling Calculator - Public Round

you mean:

 Code:
pseudo:
$a = $a + 30 - overly complicated calculations


nope, didn't even thought of that.. Would be curious too to see how much we can get those down to current scores if possible anyway.


LonkeroAdministrator
(KiX Master Guru)
2010-12-10 08:01 AM
Re: Kixgolf - Bowling Calculator - Public Round

executioner has spoken \:\)

thought about it (now, never before) and it seems to still follow the exact same logic. need to play with "/" is the hardest part of the task \:\)


BradV
(Seasoned Scripter)
2010-12-10 12:00 PM
Re: Kixgolf - Bowling Calculator - Public Round

Does anybody know J? I found this link early on, but couldn't understand it. \:\)

Bowling Calculations Using the J Language


JochenAdministrator
(KiX Supporter)
2010-12-10 03:05 PM
Re: Kixgolf - Bowling Calculator - Public Round

J is a bit cryptic,
but if we would Golf in J our scores were way lower


LonkeroAdministrator
(KiX Master Guru)
2010-12-10 09:41 PM
Re: Kixgolf - Bowling Calculator - Public Round

doubt it :P
there are already 2 J's involved in this one \:\)


JochenAdministrator
(KiX Supporter)
2010-12-12 05:23 PM
Re: Kixgolf - Bowling Calculator - Public Round

Ok, giving it up .. all I can get from the current 149 is one stroke more out of it for 150


 Code:
function a($x)
   dim $v, $b, $
   while $x
       $ = left($x,1)
       $x = right($x,~)
       if $>!
           $v = ($=X^$="/")*10 + $ - ($="/")*$v
           $a = $a + ($b+($b<2))*$v
           $b = instr("/X",$)*($x<!) + $b/2
endfunction


Even with this one, only 150:

 Code:
function a($)
   dim $v, $b, $x, $c
   while $
       $x = left($,1)
       $ = right($,~)
       if $x>!
           $c = instr("/X",$x)
           $v = ($c>)*10 + $x - ($c=1)*$v
           $a = $a + ($b+($b<2))*$v
           $b = $c*($<!) + $b/2
endfunction


So I guess the 149 Version can't be optimized anymore.
Well played Jooel, thumbs up!


AllenAdministrator
(KiX Supporter)
2010-12-12 06:03 PM
Re: Kixgolf - Bowling Calculator - Public Round

I guess that is it. Congrats guys. I'll put up the score in a bit.

AllenAdministrator
(KiX Supporter)
2010-12-12 10:12 PM
Re: Kixgolf - Bowling Calculator - Public Round

Private Round Scoring				
			Particip.	
Name	Score	Points	Points	Total
Jochen	155	5	1	6
Maciep	156	4	1	5	
Jooel	181	3	1	4	
Citrix	265	2	1	3
BradV	417	1	1	2
 
 
Public Round Scoring Bonus Name Score Points Points Total Jooel 149 5 1 6 Jochen 150 4 1 5 Maciep 156 3 0 3 Citrix 265 2 0 2 BradV 417 1 0 1
Final Scoring Jochen 11 Jooel 10 Maciep 8 Citrix 5 BradV 3


LonkeroAdministrator
(KiX Master Guru)
2010-12-12 10:41 PM
Re: Kixgolf - Bowling Calculator - Public Round

I am gonna pout now \:\(

ShaneEP
(MM club member)
2010-12-13 12:22 AM
Re: Kixgolf - Bowling Calculator - Public Round

haha nice challenge Allen. Thanks for putting it together. And thanks Brad for not having enough time to bump me to last place! ;\)

LonkeroAdministrator
(KiX Master Guru)
2010-12-13 02:08 AM
Re: Kixgolf - Bowling Calculator - Public Round

yea, thanks Allen!

JochenAdministrator
(KiX Supporter)
2010-12-13 07:39 AM
Re: Kixgolf - Bowling Calculator - Public Round

Yeah mate,
this was really great, when's the next? ;\)


BradV
(Seasoned Scripter)
2010-12-13 01:40 PM
Re: Kixgolf - Bowling Calculator - Public Round

Isn't the idea of golf the guy with the lowest score wins? I had 3!!! \:\)

AllenAdministrator
(KiX Supporter)
2010-12-13 02:35 PM
Re: Kixgolf - Bowling Calculator - Public Round

Thanks guys. Glad you guys enjoyed it. Not sure when the next one will be, be rest assured that I am constantly thinking about what would be a good challenge.