Prime number construction game

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












41














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?










share|cite|improve this question























  • What does this game have to do with nim?
    – Wojowu
    Dec 21 '18 at 6:54






  • 4




    Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
    – Eric Wofsey
    Dec 21 '18 at 6:59










  • Edited title. I think I had confused nim with this game's misère win condition.
    – scip
    Dec 21 '18 at 7:00







  • 3




    The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
    – Keith Backman
    Dec 21 '18 at 17:51










  • @KeithBackman As regards your variant I edited my answer with a P.S.
    – Robert Z
    Dec 23 '18 at 9:28















41














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?










share|cite|improve this question























  • What does this game have to do with nim?
    – Wojowu
    Dec 21 '18 at 6:54






  • 4




    Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
    – Eric Wofsey
    Dec 21 '18 at 6:59










  • Edited title. I think I had confused nim with this game's misère win condition.
    – scip
    Dec 21 '18 at 7:00







  • 3




    The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
    – Keith Backman
    Dec 21 '18 at 17:51










  • @KeithBackman As regards your variant I edited my answer with a P.S.
    – Robert Z
    Dec 23 '18 at 9:28













41












41








41


12





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?










share|cite|improve this question















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?







prime-numbers combinatorial-game-theory






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 21 '18 at 6:59

























asked Dec 21 '18 at 6:46









scip

459511




459511











  • What does this game have to do with nim?
    – Wojowu
    Dec 21 '18 at 6:54






  • 4




    Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
    – Eric Wofsey
    Dec 21 '18 at 6:59










  • Edited title. I think I had confused nim with this game's misère win condition.
    – scip
    Dec 21 '18 at 7:00







  • 3




    The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
    – Keith Backman
    Dec 21 '18 at 17:51










  • @KeithBackman As regards your variant I edited my answer with a P.S.
    – Robert Z
    Dec 23 '18 at 9:28
















  • What does this game have to do with nim?
    – Wojowu
    Dec 21 '18 at 6:54






  • 4




    Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
    – Eric Wofsey
    Dec 21 '18 at 6:59










  • Edited title. I think I had confused nim with this game's misère win condition.
    – scip
    Dec 21 '18 at 7:00







  • 3




    The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
    – Keith Backman
    Dec 21 '18 at 17:51










  • @KeithBackman As regards your variant I edited my answer with a P.S.
    – Robert Z
    Dec 23 '18 at 9:28















What does this game have to do with nim?
– Wojowu
Dec 21 '18 at 6:54




What does this game have to do with nim?
– Wojowu
Dec 21 '18 at 6:54




4




4




Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
– Eric Wofsey
Dec 21 '18 at 6:59




Seems unlikely that there's anything better you can do than just listing out the whole game tree by brute force.
– Eric Wofsey
Dec 21 '18 at 6:59












Edited title. I think I had confused nim with this game's misère win condition.
– scip
Dec 21 '18 at 7:00





Edited title. I think I had confused nim with this game's misère win condition.
– scip
Dec 21 '18 at 7:00





3




3




The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
– Keith Backman
Dec 21 '18 at 17:51




The game has a determinate winning strategy for the second player (see answers) if by 'append' you restrict adding digits to the right. A more complex version would allow a player to append a digit either to the right or the left. It's not clear to me that the game so enlarged would be so straight forward to analyze.
– Keith Backman
Dec 21 '18 at 17:51












@KeithBackman As regards your variant I edited my answer with a P.S.
– Robert Z
Dec 23 '18 at 9:28




@KeithBackman As regards your variant I edited my answer with a P.S.
– Robert Z
Dec 23 '18 at 9:28










3 Answers
3






active

oldest

votes


















69














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):



  • If the first player starts with $2$, move to $29$, and then all the moves are forced until you win at $29399999$

  • If the first player starts with $3$, move to $37$. If they then move to $373$, move to $3733$ and you will win no matter what (at either $37337999$ or $373393$). If they instead move to $379$, you move to either $3793$ or $3797$ and win immediately.

  • If the first player starts with $5$, move to $53$ and win.

  • If the first player starts with $7$, move to $71$ and then every move is forced until you win at $719333$.

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 $fracNlog N$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $frac1log(10^n)=frac1nlog(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 $frac10log(10)$ $1$-digit numbers that are valid positions in this game, and then $frac10log(10)cdotfrac102log(10)$ $2$-digit numbers, and in general $frac10^nn!log(10)^n$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$sum_n=0^inftyfrac10^nn!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$.






share|cite|improve this answer


















  • 11




    I like the heuristic argument! (+1)
    – Robert Z
    Dec 21 '18 at 8:08


















42














As mentioned by others, it isn't too hard to create the whole trie.



Player $A$ is green and Player $B$ is orange:



enter image description here



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:



enter image description here






share|cite|improve this answer


















  • 1




    Beautiful code and image!
    – Vincent
    Dec 21 '18 at 13:57


















28














Since there are "only" 83 right-truncatable primes (and 4260 left-truncatable primes), the game is a finite impartial game (like Nim) and for each position we can compute the corresponding Grundy value. So for example $g(53)=0$. This game is trivial to brute force, but by computing the Grundy values we can consider non-trivial combined games.



Note the second player, i.e. player $B$, has a winning strategy:



  • If player $A$ starts with $2$, then player $B$ appends a $9$ and the game is forced to $29399999$.


  • If player $A$ starts with $3$, then player $B$ appends a $7$, and the game is forced to $3793$, or $373393$, or $37337999$.


  • If player $A$ starts with $5$, then player $B$ appends a $3$.


  • If player $A$ starts with $7$, then player $B$ appends a $1$ and the game is forced to $719333$.


P.S. Also the variant proposed by Keith Backman, where a player is allowed to append a digit either to the right or the left, is a finite impartial game.
In fact left- or right-truncatable primes are finite, with $149677$ terms (see OEIS A137812) and the largest one is $8939662423123592347173339993799$, so any game ends in at most $31$ moves.






share|cite|improve this answer


















  • 1




    I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
    – Keith Backman
    Dec 23 '18 at 21:37










  • @KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
    – Robert Z
    Dec 24 '18 at 15:06










Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3048245%2fprime-number-construction-game%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









69














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):



  • If the first player starts with $2$, move to $29$, and then all the moves are forced until you win at $29399999$

  • If the first player starts with $3$, move to $37$. If they then move to $373$, move to $3733$ and you will win no matter what (at either $37337999$ or $373393$). If they instead move to $379$, you move to either $3793$ or $3797$ and win immediately.

  • If the first player starts with $5$, move to $53$ and win.

  • If the first player starts with $7$, move to $71$ and then every move is forced until you win at $719333$.

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 $fracNlog N$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $frac1log(10^n)=frac1nlog(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 $frac10log(10)$ $1$-digit numbers that are valid positions in this game, and then $frac10log(10)cdotfrac102log(10)$ $2$-digit numbers, and in general $frac10^nn!log(10)^n$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$sum_n=0^inftyfrac10^nn!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$.






share|cite|improve this answer


















  • 11




    I like the heuristic argument! (+1)
    – Robert Z
    Dec 21 '18 at 8:08















69














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):



  • If the first player starts with $2$, move to $29$, and then all the moves are forced until you win at $29399999$

  • If the first player starts with $3$, move to $37$. If they then move to $373$, move to $3733$ and you will win no matter what (at either $37337999$ or $373393$). If they instead move to $379$, you move to either $3793$ or $3797$ and win immediately.

  • If the first player starts with $5$, move to $53$ and win.

  • If the first player starts with $7$, move to $71$ and then every move is forced until you win at $719333$.

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 $fracNlog N$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $frac1log(10^n)=frac1nlog(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 $frac10log(10)$ $1$-digit numbers that are valid positions in this game, and then $frac10log(10)cdotfrac102log(10)$ $2$-digit numbers, and in general $frac10^nn!log(10)^n$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$sum_n=0^inftyfrac10^nn!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$.






share|cite|improve this answer


















  • 11




    I like the heuristic argument! (+1)
    – Robert Z
    Dec 21 '18 at 8:08













69












69








69






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):



  • If the first player starts with $2$, move to $29$, and then all the moves are forced until you win at $29399999$

  • If the first player starts with $3$, move to $37$. If they then move to $373$, move to $3733$ and you will win no matter what (at either $37337999$ or $373393$). If they instead move to $379$, you move to either $3793$ or $3797$ and win immediately.

  • If the first player starts with $5$, move to $53$ and win.

  • If the first player starts with $7$, move to $71$ and then every move is forced until you win at $719333$.

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 $fracNlog N$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $frac1log(10^n)=frac1nlog(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 $frac10log(10)$ $1$-digit numbers that are valid positions in this game, and then $frac10log(10)cdotfrac102log(10)$ $2$-digit numbers, and in general $frac10^nn!log(10)^n$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$sum_n=0^inftyfrac10^nn!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$.






share|cite|improve this answer














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):



  • If the first player starts with $2$, move to $29$, and then all the moves are forced until you win at $29399999$

  • If the first player starts with $3$, move to $37$. If they then move to $373$, move to $3733$ and you will win no matter what (at either $37337999$ or $373393$). If they instead move to $379$, you move to either $3793$ or $3797$ and win immediately.

  • If the first player starts with $5$, move to $53$ and win.

  • If the first player starts with $7$, move to $71$ and then every move is forced until you win at $719333$.

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 $fracNlog N$ primes less than $N$, so the probability of a random $n$-digit number being prime is about $frac1log(10^n)=frac1nlog(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 $frac10log(10)$ $1$-digit numbers that are valid positions in this game, and then $frac10log(10)cdotfrac102log(10)$ $2$-digit numbers, and in general $frac10^nn!log(10)^n$ $n$-digit numbers. Adding up all the valid positions (including the empty string at the start) gives about $$sum_n=0^inftyfrac10^nn!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$.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 21 '18 at 8:06

























answered Dec 21 '18 at 7:27









Eric Wofsey

180k12207335




180k12207335







  • 11




    I like the heuristic argument! (+1)
    – Robert Z
    Dec 21 '18 at 8:08












  • 11




    I like the heuristic argument! (+1)
    – Robert Z
    Dec 21 '18 at 8:08







11




11




I like the heuristic argument! (+1)
– Robert Z
Dec 21 '18 at 8:08




I like the heuristic argument! (+1)
– Robert Z
Dec 21 '18 at 8:08











42














As mentioned by others, it isn't too hard to create the whole trie.



Player $A$ is green and Player $B$ is orange:



enter image description here



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:



enter image description here






share|cite|improve this answer


















  • 1




    Beautiful code and image!
    – Vincent
    Dec 21 '18 at 13:57















42














As mentioned by others, it isn't too hard to create the whole trie.



Player $A$ is green and Player $B$ is orange:



enter image description here



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:



enter image description here






share|cite|improve this answer


















  • 1




    Beautiful code and image!
    – Vincent
    Dec 21 '18 at 13:57













42












42








42






As mentioned by others, it isn't too hard to create the whole trie.



Player $A$ is green and Player $B$ is orange:



enter image description here



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:



enter image description here






share|cite|improve this answer














As mentioned by others, it isn't too hard to create the whole trie.



Player $A$ is green and Player $B$ is orange:



enter image description here



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:



enter image description here







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 21 '18 at 14:56

























answered Dec 21 '18 at 10:44









Eric Duminil

2,48411018




2,48411018







  • 1




    Beautiful code and image!
    – Vincent
    Dec 21 '18 at 13:57












  • 1




    Beautiful code and image!
    – Vincent
    Dec 21 '18 at 13:57







1




1




Beautiful code and image!
– Vincent
Dec 21 '18 at 13:57




Beautiful code and image!
– Vincent
Dec 21 '18 at 13:57











28














Since there are "only" 83 right-truncatable primes (and 4260 left-truncatable primes), the game is a finite impartial game (like Nim) and for each position we can compute the corresponding Grundy value. So for example $g(53)=0$. This game is trivial to brute force, but by computing the Grundy values we can consider non-trivial combined games.



Note the second player, i.e. player $B$, has a winning strategy:



  • If player $A$ starts with $2$, then player $B$ appends a $9$ and the game is forced to $29399999$.


  • If player $A$ starts with $3$, then player $B$ appends a $7$, and the game is forced to $3793$, or $373393$, or $37337999$.


  • If player $A$ starts with $5$, then player $B$ appends a $3$.


  • If player $A$ starts with $7$, then player $B$ appends a $1$ and the game is forced to $719333$.


P.S. Also the variant proposed by Keith Backman, where a player is allowed to append a digit either to the right or the left, is a finite impartial game.
In fact left- or right-truncatable primes are finite, with $149677$ terms (see OEIS A137812) and the largest one is $8939662423123592347173339993799$, so any game ends in at most $31$ moves.






share|cite|improve this answer


















  • 1




    I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
    – Keith Backman
    Dec 23 '18 at 21:37










  • @KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
    – Robert Z
    Dec 24 '18 at 15:06















28














Since there are "only" 83 right-truncatable primes (and 4260 left-truncatable primes), the game is a finite impartial game (like Nim) and for each position we can compute the corresponding Grundy value. So for example $g(53)=0$. This game is trivial to brute force, but by computing the Grundy values we can consider non-trivial combined games.



Note the second player, i.e. player $B$, has a winning strategy:



  • If player $A$ starts with $2$, then player $B$ appends a $9$ and the game is forced to $29399999$.


  • If player $A$ starts with $3$, then player $B$ appends a $7$, and the game is forced to $3793$, or $373393$, or $37337999$.


  • If player $A$ starts with $5$, then player $B$ appends a $3$.


  • If player $A$ starts with $7$, then player $B$ appends a $1$ and the game is forced to $719333$.


P.S. Also the variant proposed by Keith Backman, where a player is allowed to append a digit either to the right or the left, is a finite impartial game.
In fact left- or right-truncatable primes are finite, with $149677$ terms (see OEIS A137812) and the largest one is $8939662423123592347173339993799$, so any game ends in at most $31$ moves.






share|cite|improve this answer


















  • 1




    I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
    – Keith Backman
    Dec 23 '18 at 21:37










  • @KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
    – Robert Z
    Dec 24 '18 at 15:06













28












28








28






Since there are "only" 83 right-truncatable primes (and 4260 left-truncatable primes), the game is a finite impartial game (like Nim) and for each position we can compute the corresponding Grundy value. So for example $g(53)=0$. This game is trivial to brute force, but by computing the Grundy values we can consider non-trivial combined games.



Note the second player, i.e. player $B$, has a winning strategy:



  • If player $A$ starts with $2$, then player $B$ appends a $9$ and the game is forced to $29399999$.


  • If player $A$ starts with $3$, then player $B$ appends a $7$, and the game is forced to $3793$, or $373393$, or $37337999$.


  • If player $A$ starts with $5$, then player $B$ appends a $3$.


  • If player $A$ starts with $7$, then player $B$ appends a $1$ and the game is forced to $719333$.


P.S. Also the variant proposed by Keith Backman, where a player is allowed to append a digit either to the right or the left, is a finite impartial game.
In fact left- or right-truncatable primes are finite, with $149677$ terms (see OEIS A137812) and the largest one is $8939662423123592347173339993799$, so any game ends in at most $31$ moves.






share|cite|improve this answer














Since there are "only" 83 right-truncatable primes (and 4260 left-truncatable primes), the game is a finite impartial game (like Nim) and for each position we can compute the corresponding Grundy value. So for example $g(53)=0$. This game is trivial to brute force, but by computing the Grundy values we can consider non-trivial combined games.



Note the second player, i.e. player $B$, has a winning strategy:



  • If player $A$ starts with $2$, then player $B$ appends a $9$ and the game is forced to $29399999$.


  • If player $A$ starts with $3$, then player $B$ appends a $7$, and the game is forced to $3793$, or $373393$, or $37337999$.


  • If player $A$ starts with $5$, then player $B$ appends a $3$.


  • If player $A$ starts with $7$, then player $B$ appends a $1$ and the game is forced to $719333$.


P.S. Also the variant proposed by Keith Backman, where a player is allowed to append a digit either to the right or the left, is a finite impartial game.
In fact left- or right-truncatable primes are finite, with $149677$ terms (see OEIS A137812) and the largest one is $8939662423123592347173339993799$, so any game ends in at most $31$ moves.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 23 '18 at 9:52

























answered Dec 21 '18 at 7:01









Robert Z

93.3k1061132




93.3k1061132







  • 1




    I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
    – Keith Backman
    Dec 23 '18 at 21:37










  • @KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
    – Robert Z
    Dec 24 '18 at 15:06












  • 1




    I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
    – Keith Backman
    Dec 23 '18 at 21:37










  • @KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
    – Robert Z
    Dec 24 '18 at 15:06







1




1




I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
– Keith Backman
Dec 23 '18 at 21:37




I guess the tow direction game was easier to analyze than I naively imagined. Thanks for the fun analysis.
– Keith Backman
Dec 23 '18 at 21:37












@KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
– Robert Z
Dec 24 '18 at 15:06




@KeithBackman It seems that also in your variant the second player has a winning strategy but the analysis is much harder.
– Robert Z
Dec 24 '18 at 15:06

















draft saved

draft discarded
















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3048245%2fprime-number-construction-game%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay