<?xml version="1.0" encoding="windows-1252"?>
<node id="103079" title="(Golf) Let's go bowling" created="2001-08-08 15:09:52" updated="2005-07-21 01:27:59">
<type id="120">
perlmeditation</type>
<author id="70099">
virtualsue</author>
<data>
<field name="doctext">
&lt;p&gt;&amp;#091;&lt;b&gt;Update&lt;/b&gt;: The winners have been posted on my home node,
along with a simple demo program which contains their code.&amp;#093;&lt;/p&gt;
Tenpin bowling, to be precise (there are many bowling games
with a variety of scoring rules).  This was partly inspired by
a chatterbox discussion many weeks ago.  For those who
have never had the pleasure, tenpin bowling is a game which consists
of &lt;b&gt;10 frames&lt;/b&gt;, in each of which you are given two tries to knock
down 10 pins.*  If you succeed on the first try, it's a 
&lt;b&gt;strike&lt;/b&gt;.  If you succeed with the second try, it's a &lt;b&gt;spare&lt;/b&gt;,
otherwise you blew it. :) &lt;p&gt; Scoring per frame works as follows:
&lt;br&gt;&lt;b&gt; Strike ('X'):&lt;/b&gt; 10 + the # of pins knocked down on the next 2 balls
&lt;br&gt;&lt;b&gt; Spare ('/'):&lt;/b&gt; 10 + the # of pins knocked down on the next ball
&lt;br&gt;&lt;b&gt; Else:&lt;/b&gt; The sum of the pins knocked down in two tries
&lt;p&gt;
The maximum score in any one frame is 30.  The minimum is 0. 
A game consisting of all strikes (AKA a 'perfect game') is 300.
The 10th frame is "special".  If a strike is thrown on the
first ball, then the player gets two more throws (to satisfy
the scoring rule above).  Likewise, if a spare is achieved
on the second ball of the 10th frame, then the player gets
one more throw. This means that a game may consist of as few
as 11 balls thrown (9 strikes in first 9 frames, then no strike
or spare in the 10th) to a maximum of 21. So, given
these rules, construct some code to score a game.
&lt;p&gt;
You can assume that you will get an array containing the
pinfall for 10 frames, e.g.
&lt;code&gt;
my @b = ('5', '/', '6', '3', 'X', 'X', '7', '0', '4', '3',
'X', '4', '/', '8', '1', '3', '/', '6');&lt;/code&gt;
(&lt;b&gt;Update&lt;/b&gt;: The above data represents a game of &lt;b&gt;146&lt;/b&gt;)&lt;p&gt;

Or, you can handle getting the pinfall data any way you want.  
I don't care, so long as the code calculates scores correctly.
&lt;p&gt;&lt;small&gt;&lt;font color="red"&gt;Thanks to [chipmunk] and [tilly] for corrections/suggestions&lt;br&gt;&lt;/font&gt;
&lt;/small&gt;&lt;br&gt;
&lt;p&gt;&lt;hr&gt;*It also consists of nasty rented shoes and ugly shirts,
the horror of which is only partially offset by the availability of
bad beer</field>
</data>
</node>
