Project Euler Lab - Problem 949

#949 - Left vs Right II

● ResearchOfficial difficulty: 100%Two-player gamesTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns. On Left's turn, for each word, Left can remove any number of letters (possibly zero), but not all the letters, from the left side of the word. However, at least one letter must be removed from at least one word. Right does the same on Right's turn except that Right removes letters from the right side of each word. The game continues until each word is reduced to a single letter. If there are more L's than R's remaining then Left wins; otherwise if there are more R's than L's then Right wins. In this problem we only consider games with an odd number of words, thus making ties impossible.

Let \(G(n, k)\) be the number of ways of choosing \(k\) words of length \(n\), for which Right has a winning strategy when Left plays first. Different orderings of the same set of words are to be counted separately.

It can be seen that \(G(2, 3)=14\) due to the following solutions (and their reorderings): \[\begin{align} (\texttt{LL},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{LR},\texttt{LR},\texttt{LR})&:1\text{ ordering}\\ (\texttt{LR},\texttt{LR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{LR},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{RL},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{RR},\texttt{RR},\texttt{RR})&:1\text{ ordering} \end{align} \]You are also given \(G(4, 3)=496\) and \(G(8, 5)=26359197010\).

Find \(G(20, 7)\) giving your answer modulo \(1001001011\).

This problem is taken from Project Euler, Problem 949.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=949. Published Saturday, 7th June 2025, 05:00 pm. Solved by 78 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact counting underlies discrete pricing lattices, scenario enumeration, and combinatorial probability (Phase 7).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.