This is a variant of Prime number building game.
Player $A$ begins by choosing a single-digit prime number. Player $B$ then appends any digit to that number such that the result is still prime, and players alternate in this fashion until one player loses by being unable to form a prime.
For instance, play might proceed as follows:
- $A$ chooses 5
- $B$ chooses 3, forming 53
- $A$ loses since there are no primes of the form 53x
Is there a known solution to this game? It seems like I might be able to try a programmatic search...or might some math knowledge help here?


The game is trivial to brute force; there just aren't very many possibilities. Assuming I have not made a mistake brute-forcing it by hand (with the aid of a computer to test for primality), the second player to move can win via the following strategy (this is not the only winning strategy):
As a heuristic for why it should not be surprising that the game is so limited, note that by the prime number theorem, there are about $\frac{N}{\log N}$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $\frac{1}{\log(10^n)}=\frac{1}{n\log(10)}$. Assuming that the primality of a number is independent from the primality of a number obtained by adding a digit at the end (which seems like a reasonable heuristic assumption), this gives that there are about $\frac{10}{\log(10)}$ $1$-digit numbers that are valid positions in this game, and then $\frac{10}{\log(10)}\cdot\frac{10}{2\log(10)}$ $2$-digit numbers, and in general $\frac{10^n}{n!\log(10)^n}$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$\sum_{n=0}^\infty\frac{10^n}{n!\log(10)^n}=e^{10/\log(10)}\approx 77$$ total positions. In fact, this heuristic estimate is not far from the actual value, which is $84$.