Your task is to sum up and output one player's score in a game of 10-pin bowling after up to 21 rolls.
The rolls are represented as a sequence of integers in your preferred method of input. Each integer corresponds to the number of pins that were knocked down in that roll.
After each round the number of pins knocked down in that round is counted into the final score. If a player knocks down all ten pins in the first roll of a round, this is a strike, and the round is over. Otherwise, the round lasts for one more roll. If the second roll of a round knocks down all the remaining pins, this is a spare.
For each strike there is a bonus equal to the sum of pins knocked down in the two next rolls. For each spare there is a bonus equal to the number of pins knocked down in the next roll.
The 10th and final round, the player may be granted extra rolls: In case of a strike, the player gets two more rolls to make up his strike bonus. In case of a spare, the player gets one more roll.
Input: 4 3 8 2 7 1 10 7 3 0 10 2 2 10 10 5 4 Output: 131 Input: 10 10 9 1 7 3 2 7 10 1 9 10 7 1 10 10 10 Output: 183
- You may assumed that the input is valid.
- As per Mego's comment I have loosened the requirements for the input/output methods to meet our current standard.
- Answers in languages that are newer than the challenge are allowed
- Shortest code wins!