TITLE: Prime number construction game
QUESTION [50 upvotes]: 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?

REPLY [44 votes]: As mentioned by others, it isn't too hard to create the whole trie.
Player $A$ is green and Player $B$ is orange:

For reference purposes, here's the corresponding Python code. It uses networkx and graphviz:
import networkx as nx
from networkx.drawing.nx_agraph import to_agraph

def is_prime(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    for d in range(3, int(n**0.5) + 1, 2):
        if n % d == 0:
            return False
    return True


def add_prime_leaves_recursively(current_number=0, current_representation='',
                                 base=10, graph=nx.DiGraph(), level=0,
                                 colors=['#FF851B', '#2E8B57']):
    graph.add_node(current_number,
                   label=current_representation,
                   color=colors[level % 2])
    for next_digit in range(base):
        next_number = current_number * base + next_digit
        if is_prime(next_number):
            graph.add_edge(current_number, next_number)
            add_prime_leaves_recursively(
                next_number,
                current_representation + '0123456789ABCDEFGHIJ'[next_digit],
                base, graph, level + 1)
    return graph


G = add_prime_leaves_recursively(base=10)
G.nodes[0]['color'] = 'black'

A = to_agraph(G)
A.draw('prime_number_construction_game.png', prog='dot')

This code can generate the diagram for any base below 20. The game is boring in base 3: