Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: (Golf) Let's go bowling

by tachyon (Chancellor)
on Aug 08, 2001 at 21:54 UTC ( #103134=note: print w/ replies, xml ) Need Help??


in reply to (Golf) Let's go bowling

I don't know if my logic is wrong but I get a score of 162. I havn't bothered to obfuscate it and print out a score sheet to show the frame by frame results.

my @b = ('5', '/', '6', '3', 'X', 'X', '7', '0', '4', '3', 'X', '4', '/', '8', '1', '3', '/', '6'); print "Frame tog ball score total\n"; print score(@b),"\n\n"; print "Frame tog ball score total\n"; print score(('X')x12); sub score { $i=0;$f=1;$t=1;$score=0; for (@_) { last if $f>10; if(/X/) { $s=10+n($_[$i+1])+n($_[$i+2]); $t=1 } elsif(/\//) { $s=10+n($_[$i+1]); $t=1 } else { $s=$_; $t^=1 # flip the toggle with XOR } $score+=$s; printf "%2d %d %s %2d %3d\n",$f, $t, $_, $s, $scor +e; $t&&$f++; # count the frames $i++; } sub n{$v=pop;$v=~/[X\/]/?10:$v} return $score } __END__ Frame tog ball score total 1 0 5 5 5 1 1 / 16 21 2 0 6 6 27 2 1 3 3 30 3 1 X 27 57 4 1 X 17 74 5 0 7 7 81 5 1 0 0 81 6 0 4 4 85 6 1 3 3 88 7 1 X 24 112 8 0 4 4 116 8 1 / 18 134 9 0 8 8 142 9 1 1 1 143 10 0 3 3 146 10 1 / 16 162 162 Frame tog ball score total 1 1 X 30 30 2 1 X 30 60 3 1 X 30 90 4 1 X 30 120 5 1 X 30 150 6 1 X 30 180 7 1 X 30 210 8 1 X 30 240 9 1 X 30 270 10 1 X 30 300 300

Did I miss something?

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


Comment on Re: (Golf) Let's go bowling
Download Code
Replies are listed 'Best First'.
Re: Re: (Golf) Let's go bowling
by nardo (Friar) on Aug 08, 2001 at 22:04 UTC
    One reason you're getting a higher score is because you aren't dealing with spares correctly. Look at the score after the first frame, it's 21 which is impossible for a spare frame. When a frame is a spare, you count the first ball twice because the ten pins that you assign a '/' includes the pins knocked down with the first ball which you already counted (i.e. I knock down 5 pins then another 5 pins for a spare -- you count 5 pins and another 10 pins for the spare which is wrong).

      So what is the score after the first frame? Do you ignore the 5 and say it is 10+6=16?

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Yes, the score for the first frame is 16.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://103134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2015-07-28 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (256 votes), past polls