part2

Function part2 

Source
pub fn part2(input: &((usize, usize), (usize, usize))) -> usize
Expand description

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.

Each player can be in position 1 to 10 and can have a score from 0 to 20 (as a score of 21 ends the game). This is a total of (10 × 21)² = 44,100 possible states. For speed this can fit in an array with perfect hashing, instead of using a slower HashMap.