Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: (Golf) Let's go bowling

by nardo (Friar)
on Aug 08, 2001 at 21:58 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103137]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found