|
|
|||||||
Please post your code... |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
so yeah....almost the same code |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Nice one Jooel, why haven't I thought about that before |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Maybe I haven't had this constellation long enough to bug my eye.. It was the improvement from 163 to 157. |
||||||||
|
|
|||||||
oh. doesn't really hurt you eyes when you think "this baby is my leader" |
||||||||
|
|
|||||||
ok, now to squeeze one or more out of my baby.. that'll be hard. |
||||||||
|
|
|||||||
don't have time to look at it now but there should be more to be shaved in there. still looks too "messy" |
||||||||
|
|
|||||||
clever code you guys managed to put out. nice. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Someone mind explaining this line? Code: 2*($=X)^$="/" |
||||||||
|
|
|||||||
basicly the same as 2*($=x)+($='/') |
||||||||
|
|
|||||||
... 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 |
||||||||
|
|
|||||||
wohoo! I tried something similar but you got it working! way to go!!!! |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
hehe, yeah, quite obvious |
||||||||
|
|
|||||||
Originally Posted By: Allen Please post your code... When does it end? Countdown clock? |
||||||||
|
|
|||||||
Ey Ey Capitan... |
||||||||
|
|
|||||||
Brain hurts big time ... |
||||||||
|
|
|||||||
Curious... anyone try to do it with 30 pins as a max per frame and subtract accordingly? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Does anybody know J? I found this link early on, but couldn't understand it. Bowling Calculations Using the J Language |
||||||||
|
|
|||||||
J is a bit cryptic, but if we would Golf in J our scores were way lower |
||||||||
|
|
|||||||
doubt it :P there are already 2 J's involved in this one |
||||||||
|
|
|||||||
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! |
||||||||
|
|
|||||||
I guess that is it. Congrats guys. I'll put up the score in a bit. |
||||||||
|
|
|||||||
|
||||||||
|
|
|||||||
I am gonna pout now |
||||||||
|
|
|||||||
haha nice challenge Allen. Thanks for putting it together. And thanks Brad for not having enough time to bump me to last place! |
||||||||
|
|
|||||||
yea, thanks Allen! |
||||||||
|
|
|||||||
Yeah mate, this was really great, when's the next? |
||||||||
|
|
|||||||
Isn't the idea of golf the guy with the lowest score wins? I had 3!!! |
||||||||
|
|
|||||||
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. |