Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: (Golf) Let's go bowling

by nardo (Friar)
on Aug 08, 2001 at 21:58 UTC ( #103137=note: print w/ replies, xml ) Need Help??


in reply to (Golf) Let's go bowling

Doing it with substitutions

sub bowlscore { my $t; $_=join(',',@_); while(s/X,X,X/30,X,X/){} s!X,X,(\d)!20+$1.",X,$1"!eg; s!X,(\d),(\d)!10+$1+$2.",$1,$2"!eg; s!X,\d,/!20,1,/!g; s!\d,/,(\d)(\b)!10+$1.",$1$2"!eg; s!\d,/(?=,\d\d)!20!g; s!(\d\d)(,\d){1,2}$!$1!; map($t+=$_,split(/,/)); $t; }
223 chars not counting the unnecessary whitespace for the body of the function. It's not the lowest bytecount here, but at least it's lower than my bowling highscore.

Update: This fixes a bug pointed out by dragonchild
sub bowlscore { my $t; $_=join(',',@_); while(s/X,X,X/30,X,X/){} s!X,X,(\d)!20+$1.",X,$1"!eg; s!X,(\d),(\d)!10+$1+$2.",$1,$2"!eg; s!X,\d,/!20,0,/!g; s!/,X!20!; s!\d,/,(\d)(\b)!10+$1.",$1$2"!eg; s!\d,/(?=,\d\d)!20!g; s!(\d\d)(,\d){1,2}$!$1!; map($t+=$_,split(/,/)); $t; }
10 chars added.

And another correction:
s!\d,/,(\d)(\b)!10+$1.",$1$2"!eg;
should be
while(s!\d,/,(\d)(\b)!10+$1.",$1$2"!eg){}
for multiple spare frames in a row to work.


Comment on Re: (Golf) Let's go bowling
Select or Download Code
Re: Re: (Golf) Let's go bowling
by dragonchild (Archbishop) on Aug 08, 2001 at 22:22 UTC
    I can cut you down to 163 characters by doing standard golfings ($_=join',',@_;, for example). However, you get 189 if given ('X')x12. (I'm not doing much better, myself. *winces*

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

      you get 189 if given ('X')x12

      I think you copied my code wrong
      print &bowlscore(('X')x12), "\n";
      prints 300 on my machine.
        You're right. I did copy it down wrong. However, you still fail on
        qw(0 / X 0 / X 0 / X 0 / X 0 / X 0 /) 201 (should be 200) qw(X 0 / X 0 / X 0 / X 0 / X 0 / X) 181 (should be 200)

        ------
        /me wants to be the brightest bulb in the chandelier!

        Vote paco for President!

Re: Re: (Golf) Let's go bowling
by dragonchild (Archbishop) on Aug 08, 2001 at 22:58 UTC
    You still have a bug in the 3rd case, where you go strike, 0-spare, strike, 0-spare, etc. That's also equal to 200, not 210.

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2014-09-21 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls