Twenty One
The description of the Twenty One problem leaves a few details vague.
- A player wins by getting a score of 21.
- As soon as a player gets a score of 21, the game ends. The other player does not get a turn, and the first player does not keep drawing.
- A player’s turn does not end until they fail to find any shells.
There are two important examples.
Example 1
The sequence of numbers is:
2 2 2 2 2 2 2 2 2 2 1
This is just the first player, running their score up to 21 and winning. The second player never even gets a turn.
Example 2
The sequence of numbers is:
2 2 2 2 2 2 1 0 0 2 2 2 2
A A A A A A A A B A A A A
The first player (A) runs their score up to 13 and then cannot find
any shells. According to the rules, their score is then reset to zero
(see below). The second player (B) does not find any shells. The first
player (A) then finds four 2’s, giving them a final score of 8. Since
nobody has a score of 21, this game is UNDECIDED
.
Problem Statement
Dory likes playing the game of 21 with her other fish friends in the Open Ocean Exhibit. Players take turns finding sea shells - a regular sea shell is worth 1 point, a purple sea shell (her mom’s favorite!) is worth 2 points, and finding no sea shells is worth 0 points. A player loses their turn when they can find no more sea shells. If a player has 13 points on their turn and they can’t find a sea shell, then their score goes back to 0. If a player goes over 21 points on their turn, then their score goes back to 13 (they don’t lose their turn). You’re tasked with a program to help automate score keeping.