go ahead... be a heretic PerlMonks

### Re (tilly) 1: (Golf) Let's go bowling

by tilly (Archbishop)
 on Aug 09, 2001 at 00:00 UTC ( #103200=note: print w/replies, xml ) Need Help??

in reply to (Golf) Let's go bowling

I would strongly appreciate someone laying out the calculation in detail for the above coming out with an answer of 146. The following chart that counts bottom to top for obvious reasons gives me 164.
ball score total 5 5 164 / 16 159 6 6 143 3 3 137 X 27 134 X 17 107 7 7 90 0 0 83 4 4 83 3 3 79 X 20 76 4 4 56 / 18 52 8 8 34 1 1 26 3 3 25 / 16 22 6 6 6
If that is correct, then the following code is correct. If it is wrong, then I misunderstand the problem and don't have a solution at 103 characters.
sub hole { # 1 2 3 4 5 6 +7 8 9 10 #234567890123456789012345678901234567890123456789012345678901234567890 +1234567890123456789012345678901012345 \$i=\$s=0;for(@_=(0,0,reverse@_)){\$s+=\$_[\$i-1]+\$_[\$i-(/X/?2:-1)],\$_=/X/? +10:10-\$_[\$i+1]if/\D/;\$s+=\$_;\$i++}\$s }

Replies are listed 'Best First'.
Re: Re (tilly) 1: (Golf) Let's go bowling
by tachyon (Chancellor) on Aug 09, 2001 at 00:11 UTC

Here is the frame by frame score (ignore the toggle :-)

Frame tog ball score total 0 5 1 1 / 16 16 0 6 2 1 3 9 25 3 1 X 27 52 4 1 X 17 69 0 7 5 1 0 7 76 0 4 6 1 3 7 83 7 1 X 20 103 0 4 8 1 / 18 121 0 8 9 1 1 9 130 0 3 10 1 / 16 146 6

cheers

tachyon

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

D'oh. That brings my idea of working in reverse up to 133.
sub hole { \$i=\$s=0;\$s-=\$_[-1]if"@_[-2,-1]"=~m!/|X!;map{\$s+=\$_[\$i-1],\$_=/X/?(\$s+=\$ +_[\$i-2],10):10-\$_[\$i+1]if/\D/;\$s+=\$_;\$i++}@_=(0,0,reverse@_);\$s }

Short though this is it fails the test suite

print score(qw(5 / 6 3 X X 7 0 4 3 X 4 / 8 1 3 / 6)),"--> 146\n"; print score(qw(X X X X X X X X X X X X)), "--> 300\n"; print score(qw(0 / X 0 / X 0 / X 0 / X 0 / X 0 /)),"--> 200\n"; print score(qw(X 0 / X 0 / X 0 / X 0 / X 0 / X 0)),"--> 200\n"; sub score { \$i=\$s=0;\$s-=\$_[-1]if"@_[-2,-1]"=~m!/|X!;map{\$s+=\$_[\$i-1],\$_=/X/?(\$s+=\$ +_[\$i-2],10):10-\$_[\$i+1]if/\D/;\$s+=\$_;\$i++}@_=(0,0,reverse@_);\$s } __END__ 146--> 146 330--> 300 210--> 200 210--> 200

cheers

tachyon

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

This appears to fail on runs with a spare or strike in the bonus balls, e.g.
qw(1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 X X 0) -> 75 should be 65 qw(9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 / X) -> 111 should be 101 qw(X X X X X X X X X X X X) -> 330 should be 300 qw(0 / X 0 / X 0 / X 0 / X 0 / X 0 /) -> 210 should be 200
from my test suite.
--
Brovnik
Re: Re (tilly) 1: (Golf) Let's go bowling
by chipmunk (Parson) on Aug 09, 2001 at 00:35 UTC
There are two mistakes in your solution. First, the bonus ball(s), i.e. the extra ball for a spare or extra two balls for a strike in the tenth frame, are only counted once. You've counted the 6 at the end twice.

Second, when a spare is scored, that frame scores exactly 10 plus the next ball. You're scoring 10 for the spare, plus the first ball, plus the next ball. For example, for 3 / 6, you counted the three twice, once by itself and once as part of the spare.

Here's how this would actually be scored, going bottom to top:

ball score total 5 - 146 / 16 146 6 6 130 3 3 124 X 27 121 X 17 94 7 7 77 0 0 70 4 4 70 3 3 66 X 20 63 4 - 43 / 18 43 8 8 25 1 1 17 3 - 16 / 16 16 6 -

Create A New User
Node Status?
node history
Node Type: note [id://103200]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-02-19 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (266 votes). Check out past polls.

Notices?