# Le Monde puzzle [#1115]

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**R – Xi'an's Og**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**A** two-person game as Le weekly Monde current mathematical puzzle:

Two players Amaruq and Atiqtalik are in a game with n tokens where Amaruq chooses a number 1

The run of a brute force R code like

B=rep(-1,200);B[1:9]=1 for (i in 10:200){ v=matrix(-2,9,9) for (b in 2:9){ for (a in (2:9)[-b+1]) for (d in c(1,a,b)){ e=i-d-c(1,a,b) if (max(!e)){v[a,b]=max(-1,v[a,b])}else{ if (max(e)>0) v[a,b]=max(v[a,b],min(B[e[which(e>0)]]))}} B[i]=max(B[i],min(v[v[,b]>-2,b]))}

always produces 1’s in B, which means the first player wins no matter… I thus found out (from the published solution) that my interpretation of the game rules were wrong. The values A and B are fixed once for all and each player only has the choice between withdrawing 1, A, and B on her turn. With the following code showing that Amaruq looses both times.

B=rep(1,210) for(b in(2:9)) for(a in(2:9)[-b+1]) for(i in(2:210)){ be=-2 for(d in c(1,a,b)){ if (d==i){best=1}else{ e=i-d-c(1,a,b) if (max(!e)){be=max(-1,be)}else{ if (max(e)>0)be=max(be,min(B[e[which(e>0)]]))}}} B[i]=be}

To

**leave a comment**for the author, please follow the link and comment on their blog:**R – Xi'an's Og**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.