Rolling the Dirac dice 3 times results in 27 quantum universes. However, the dice total is
one of only 7 possible values. Instead of handling 27 values, we encode the possible dice
totals with the number of times that they occur. For example, a score of 3 (1 + 1 + 1) only
happens once in the 27 rolls, but a score of 6 happens a total of 7 times.
The initial deterministic dice roll total is 6 (1 + 2 + 3) and increases by 9 each turn.
An interesting observation is that since the player’s position is always modulo 10, we can
also increase the dice total modulo 10, as (a + b) % 10 = (a % 10) + (b % 10). Additionally,
both players end up back in the same position every 10 moves, so we can compute the score per
batch of 10 moves before simulating only the remainder.
Memoization is the key to solving part two in a
reasonable time. For each possible starting universe we record the number of winning and losing
recursive universes so that we can reuse the result and avoid unnecessary calculations.