Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

[Update: The winners have been posted on my home node, along with a simple demo program which contains their code.]

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 10 frames, in each of which you are given two tries to knock down 10 pins.* If you succeed on the first try, it's a strike. If you succeed with the second try, it's a spare, otherwise you blew it. :)

Scoring per frame works as follows:
Strike ('X'): 10 + the # of pins knocked down on the next 2 balls
Spare ('/'): 10 + the # of pins knocked down on the next ball
Else: The sum of the pins knocked down in two tries

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.

You can assume that you will get an array containing the pinfall for 10 frames, e.g.

my @b = ('5', '/', '6', '3', 'X', 'X', '7', '0', '4', '3', 'X', '4', '/', '8', '1', '3', '/', '6');
(Update: The above data represents a game of 146)

Or, you can handle getting the pinfall data any way you want. I don't care, so long as the code calculates scores correctly.

Thanks to chipmunk and tilly for corrections/suggestions


*It also consists of nasty rented shoes and ugly shirts, the horror of which is only partially offset by the availability of bad beer

In reply to (Golf) Let's go bowling by virtualsue

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (6)
    As of 2014-12-27 09:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (176 votes), past polls