Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

Chapter 40. Bowling Scores

Bowling is played in ten frames, each of which allows one or two deliveries. If all ten pins are bowled over in the first delivery, there is no second delivery.

Each frame has a score based on the delivery in that frame, as well as the next one or two deliveries. This means that the score for a frame may not necessarily be posted at the end of the frame. It also means that the tenth frame may require a total of three deliveries to resolve the scoring.

  • Rule A. The score for a frame is the total pins bowled over during that frame, if the number is less than ten (an open frame, or error or split depending some other rules beyond the scope of this problem).

  • Rule B. If all ten pins are bowled over on the first delivery (a strike), the score for that frame is 10 + the next two deliveries.

  • Rule C. If all ten pins are bowled over between the first two deliveries (a spare), the score for that frame is 10 + the next delivery.

A game can be as few as twelve deliveries: ten frames plus two additional deliveries in the tenth frame to resolve the rule B scoring. A game can be as many as twenty deliveries: ten open frames of less than 10 pins bowled over during the frame.

There is a relatively straight-forward annotation for play. Each frame has two characters to describe the pins bowled during the delivery. The final frame has three characters for a total of 21 characters.

Rule A: If the frame is open, the two characters are the two deliveries; the total will be less than 10. If a delivery fails to bowl over any pins, a - is used instead of a number.

Rule B: If the frame is strike, the two characters are X␣. No second delivery was made.

Rule C: If the frame is a spare, the first character is the number of pins on the first delivery. The second character is a /.

For example:

8/9-X␣X␣6/4/X␣8-X␣XXX

This can be analyzed into ten frames as follows:

Frame First delivery Second delivery Scoring rule Frame Score Total
1 8 2 C- spare = 10 + next delivery 19 19
2 9 - A- open = 9 9 28
3 10 (not taken) B- strike = 10 + next 2 deliveries 26 54
4 10 (not taken) B- strike = 10 + next 2 deliveries 20 74
5 6 4 C- spare = 10 + next delivery 14 88
6 4 6 C- spare = 10 + next delivery 20 108
7 10 (not taken) B- strike = 10 + next 2 deliveries 18 126
8 8 - A- open = 8 8 134
9 10 (not taken) B- strike = 10 + next 2 deliveries 30 164
10 10 10 and 10 B- strike = 10 + next 2 deliveries, two extra deliveries are taken during this 10th frame. 30 194

Each of the first nine frames has a two-character code for each delivery. There are three forms:

  • X␣ .

  • n / where n is - or 1-9.

  • mm where m is - or 1-9. The two values cannot total to 10.

The tenth frame has a three-character code for each of the deliveries. There are three forms:

  • XXX

  • n / r where n is -, 1-9 and r is X, -, 1-9.

  • mm where m is - or 1-9. The two values cannot total to 10.

Write a valid( game ) function that will validate a 21-character string as describing a legal game.

Write a scoring function, scores( game ), that will accept the 21-character scoring string and produce a sequence of frame-by-frame totals.

Write a reporting function, scoreCard( game ) will use the validation and scoring functions to produce a scorecard. The scorecard shows three lines of output with 5 character positions for each frame.

The top line has the ten frame numbers: 2 digits and 3 spaces for each frame.

The second line has the character codes for the delivery: 2 or 3 characters and 3 or 2 spaces for each of the ten frames.

The third line has the cumulative score for each frame: 3 digit number and 2 spaces.

The game shown above would have the following output.

 1    2    3    4    5    6    7    8    9   10   
8/   9-   X    X    6/   4/   X    8-   X    XXX
 19   28   54   74   88  108  126  134  164  194

 
 
  Published under the terms of the Open Publication License Design by Interspire