#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:
Write scorecard(rolls) that returns the scoreboard: a list of 10 numbers, the running total after each frame.
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.
rolls is always a complete and valid game: 11 to 21 numbers from 0 to 10.First solves only, ranked by stars and then time.