Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: (Golf) Let's go bowling

by petral (Curate)
on Aug 13, 2001 at 22:01 UTC ( #104509=note: print w/replies, xml ) Need Help??


in reply to (Golf) Let's go bowling

Just for the record, here's a fairly straightforward one treating the score as a string.  It replaces '/' with the appropriate count and dupes the following char (unless it's an extra ball), replacing X with x to avoid processing the X twice.  Then it dupes the 2 chars following each X (again, except for extras), and tallies.  It passes all of the above tests and comes in at 96 chars:
sub score { $_=pop; # 7 s#(.)/(?=(.).|.?$)#$1.($1?10-$1:'x').lc$2#ge; # 45 s/X(?=(..).)/X$1/g; # 19 y/Xx/9/+eval join'+',/./g # 25 } # ___ # 96
Only one problem, it fails for a strike in the 9th frame and no extra balls in the 10th!  /X\d\d$/ matches either. (Also, there's no agreement on whether the args passed in have to match the orginal @b example.) Patching for those makes it 123 :-( :
sub fullscore { $_=join'',@_; # 13 s/^(X|\d.){10}$/$&0/; # 21 s#(.)/(?=(.).|.?$)#$1.($1?10-$1:'x').lc$2#ge; # 45 s/X(?=(..).)/X$1/g; # 19 y/Xx/9/+eval join'+',/./g # 25 } # ___ # 123


  p

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://104509]
help
Chatterbox?
[perldigious]: Quick question, is undef %hash a recommended/good way to delete an entire hash structure from memory? Or sould I be doing it some other way?
[1nickt]: The best way is to scope it tightly so it just goes away when you are finished with it.
[perldigious]: but... but... perldigious is the unvirtuous kind of lazy in this case. :-)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-07-21 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (335 votes). Check out past polls.