Dice bust scorer
EasyOnline Assessment
Score one round of a two-dice game called Push Your Luck.
A player has a running total. In a round they roll two dice again and again; rolls lists the rolls they will make in order, each as [a, b]. A round has a score that starts at 0, and each roll is handled as follows:
- If exactly one die shows a 1, it is a bust: the round's score is lost, the round ends, and
totalis unchanged. - If both dice show 1 (snake eyes), the round ends and the player loses everything:
totalbecomes 0. - Otherwise the roll is worth
a + bpoints, and doubled ifa == b(so[3, 3]is worth 12). Add it to the round's score. If the round's score is now 30 or more, the player banks it automatically: the score is added tototaland the round ends.
When a round ends, any remaining rolls are never made, so they do not matter. If rolls runs out before anything ends the round, the player stops and banks the current score.
Input: total, the player's total before the round, and rolls, a list of [a, b] pairs.
Output: a list [newTotal, rollsUsed], where rollsUsed is the number of rolls that were actually made (including the roll that ended the round).
Example 1
- Input:
- [12,[[3,4],[2,2],[5,6]]]
- Output:
- [38,3]
- Explanation
- Rolls 3+4 = 7 and the double 2+2 = 4, doubled to 8, make 15, then 5+6 = 11 gives 26. That never reaches 30, so the player keeps all of it when the rolls run out: 12 + 26 = 38, using all 3 rolls.
Example 2
- Input:
- [40,[[6,6],[4,5],[1,3]]]
- Output:
- [73,2]
- Explanation
- The double of sixes scores (6+6) x 2 = 24, then 4+5 = 9 makes 33, which is at least 30, so the round is banked right there: 40 + 33 = 73 after 2 rolls. The roll with a 1 that follows is never made.
Example 3
- Input:
- [25,[[5,5],[2,1],[1,1]]]
- Output:
- [25,2]
- Explanation
- 5+5 is a double worth 20. The next roll contains a single 1, a bust: the round's 20 points are lost and the round ends after 2 rolls, leaving the total at 25. The
[1, 1]after it is never reached.
Constraints
0 <= total <= 100,0000 <= rolls.length <= 300- each roll is
[a, b]with1 <= a, b <= 6