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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|