25
3
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.
Scoring
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.
Examples
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
Rules
- 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!
Do I remember correctly that bonuses don´t stack? – Titus – 2017-04-22T21:58:21.040
@Titus I'm not exactly sure what you mean, but no, bonuses don't "stack", i.e, for a strike you add the number of pins that are knocked down in the two next rolls, regardless of whether they are strikes or not. So maximum score for one strike is 30 points, and maximum for a whole game is 300. – daniero – 2017-04-23T00:39:29.413
Do distinct command line arguments qualify as
space separated integers
? – Titus – 2017-04-23T11:07:05.7631@Titus sure. This is an old post - Today's consensus on acceptable input methods was not established at this point. Actually, I don't see now why today's standard shouldn't apply to this (including function parameters etc), although I'm not a fan of changing the rules of the challenge retroactively. – daniero – 2017-04-23T14:16:37.747
1@daniero The usual advice is that it's acceptable to loosen the rules to fit modern standards, so long as it doesn't drastically change the challenge. – Mego – 2017-08-24T08:41:55.963
@Mego sounds reasonable. I've updated the rules. – daniero – 2017-08-24T17:05:46.567
Do we have to check if the input is valid? Right amount of rolls, right amount of pins per round, etc? – JAD – 2017-08-24T17:07:59.103
@JarkoDubbeldam No, that was never intended. I will add an clarification – daniero – 2017-08-24T17:10:25.260