Editor

Bowling Scorecard

#313 · Simulation · Intermediate · 75 XP · about 18 min

A game of ten-pin bowling has 10 frames, and rolls lists how many pins fell on each roll of one complete game, in order. The scoring rules:

  • In each of frames 1 to 9 the player rolls at most twice. Knocking down all 10 pins with the first roll is a strike, and the frame ends at once.
  • Knocking down all 10 pins with the two rolls of a frame is a spare.
  • A frame that is neither scores the pins knocked down in it. A spare scores 10 plus the pins of the next roll. A strike scores 10 plus the pins of the next two rolls.
  • In frame 10, a strike or a spare earns bonus rolls so that its bonus can be counted: one extra roll after a spare, two after a strike. Frame 10 scores all the pins of its two or three rolls.

Write scorecard(rolls) that returns the scoreboard: a list of 10 numbers, the running total after each frame.

Examples

scorecard([10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1])
# returns [20, 39, 48, 66, 74, 84, 90, 120, 148, 167]

scorecard([10] * 12)
# returns [30, 60, 90, 120, 150, 180, 210, 240, 270, 300]

scorecard([0] * 20)
# returns [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

In the first game, frame 1 is a strike followed by 7 and 3, so it scores 20. Frame 2 is a spare (7 and 3) followed by a 9, so it scores 19 and the total becomes 39. The last frame is a strike with its two bonus rolls, 8 and 1, scoring 19.

Constraints

  • rolls is always a complete and valid game: 11 to 21 numbers from 0 to 10.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.