Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

(tye)Re: (Golf) Let's go bowling

by tye (Cardinal)
on Aug 11, 2001 at 12:00 UTC ( #104124=note: print w/ replies, xml ) Need Help??


in reply to Re: (Golf) Let's go bowling
in thread (Golf) Let's go bowling

I think you misunderstood what I was thinking. This routine requires a single string instead of a list of single-character scalars and weighs in at just 103 strokes!

sub bowl { $_=pop; s#(\d)([\d/](?=(.)))|X(?=(..))|.#$3?"X$3":$4?"X$4":$1.$2#ge; s#\d/#/#g; map{(y./X.aa.)x hex}split// }

Or, you can handle getting the pinfall data any way you want. I don't care, so long as the code calculates scores correctly.
...so I don't consider this cheating. (: You can replace theh first statement with $_=join'',@_; if you disagree and I'm still only at 109. This is a fairly long thread so I'm almost certain I missed something, but I didn't see any scores that low.

Update: I can golf that down a bit if you don't mind me using more undef strings which would generate warnings if such were enabled (the original only does that for the bonus balls). Also, I golfed the tr down by one stroke:

sub bowl { $_=pop; s#(\d)(\d|/(?=(.)))|X(?=(..))|.#$3.$4?"X$3$4":$1.$2#ge; s#\d/#/#g; map{(y./X.a.)x hex}split// }
which gets me to 98!

Oh, and I did cheat in that you have to call this in a scalar context or you get what looks like a binary number. I'll take a 2-stroke penalty ("0+") for that if required.

Update: Darn, I just noticed that a late bug fix (for /X\d\d/ in the tenth frame) got left out but that fix breaks things worse. An alternate bug fix hurts a little more:

sub bowl { $_=pop; s#(\d)(\d(?=.)|/(?=(.)))|X(?=(..))|.#$3.$4?"X$3$4":$1.$2#ge; s#\d/#/#g; map{(y./X.a.)x hex}split// }
which puts me back up at 103.

        - tye (but my friends call me "Tye")


Comment on (tye)Re: (Golf) Let's go bowling
Select or Download Code
(tye)Re2: (Golf) Let's go bowling (98!)
by tye (Cardinal) on Aug 13, 2001 at 19:27 UTC

    I got down to 98:

    sub bowl { $_=pop; s#(\d)(\d|(/))(?=(.))|X(?=(..))|.#$3.$5?"X$4$5":$1.$2#ge; s#./#X#g; map{(y.X.a.)x hex}split// }

            - tye (but my friends call me "Tye")
      Same thing that caught me:
      print bowl(join'', qw(0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 X 3 4)); 53!
      should be 60.
      (but you can save a few strokes using /./g for split//)

        p

        Darn. I noticed elsewhere in the thread about being sure to not count the bonus balls twice but missed the stuff about there being no good trick to tell whether X\d\d$ is a final frame with bonus balls or just the two final frames (other than counting frames). ):

        I really didn't want to hard-code the number of frames because sometimes I'll bowl a "short game" when we run out of time. So here is an entry at 113 strokes that optionally lets you specify how many frames you shortened your game (you can even pass in a negative value for "extra long games"):

        sub bowl { ($_,$n)=@_; s#(\d)(\d|/(?=(.)))|X(?=(..))|.# ($3.$4?"X$3$4":$1.$2,"")[9<$n++]#ge; s#./#X#g; map{(y.X.a.)x hex}split// } chomp( @ARGV=<DATA> ) if ! @ARGV; for my $line ( @ARGV ) { print "$line = ", 0+bowl($line), "\n "; for( 0..9 ) { print " ",0+bowl($line,9-$_); } print $/; } __END__ 81633470434/72813/62 81633470434/72813/X18 X00X00X00X00X00 00X00X00X00X00X00 X11X11X11X11X11 11X11X11X11X11X11 5/63XX7043X4/813/6
        This even allowed me to add a test suite that shows the score at each frame.

                - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-08-02 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (53 votes), past polls