Project Euler Problem 949

Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns.

Project Euler Problem 949

Solution

Answer: 726010935

Treat each word as a partisan combinatorial game.

For a word $w$:

  • terminal positions are $L=+1$ and $R=-1$,
  • a nonterminal word has value

$$G(w)={,G(\text{proper suffixes})\mid G(\text{proper prefixes}),}.$$

For several words played simultaneously, the game is the disjunctive sum of the individual games, and Right wins moving second exactly when the total game is $\le 0$.

The key structural fact is that every word of length $n$ reduces to either:

  • a cold dyadic rational (numeric value), or
  • a hot switch whose mean is a dyadic rational.

One can recursively enumerate all $2^{20}$ words, compute their canonical values, build the distribution of values, and then convolve that distribution $7$ times (FFT / DP convolution). Summing all combinations whose total value is $\le 0$ gives $G(20,7)$.

A Python implementation following this recursion reproduces the checks

  • $G(2,3)=14$,
  • $G(4,3)=496$,
  • $G(8,5)=26359197010$,

and finally yields

$$G(20,7)\equiv 726010935 \pmod{1001001011}.$$

This matches published solution repositories for Project Euler problem 949.

Answer: 726010935