# Le Monde puzzle [#835]

**Xi'an's Og » R**, 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.

**T**he current puzzle is apparently suffering from combinatoric complexity :

N persons (with 20≤N≤23)are sitting around a round table and everyone has a green or red token. Both colours are represented. First, each player with a red token take the token of the player immediately to her or his left. Second, each player with at least one green token gives it to the player next to theplayer immediately to her or his left. By that time, everyone has a token in front of her or him. What are the possible values of N?

**I** first tried a brute force approach where I fill a table at random and apply the rules:

sole=FALSE while (!sole){ N=sample(20:23,1) arthur=merlin=cbind(sample(1:2,N,rep=TRUE),rep(0,N),rep(0,N)) #Move 1 merlin[arthur[,1]==1,2]=arthur[(1:N)[arthur[,1]==1]%%N+1,1] merlin[(1:N)[arthur[,1]==1]%%N+1,1]=0 #Move 2 mordred=merlin green=(1:N)[apply(merlin,1,max)==2] mordred[(green+1)%%N+1,3]=merlin[green,1] mordred[green,1]=0 #Solution sole=(min(apply(mordred,1,max))>0) } mordred

**A**fter a rather long while that had me fear the loop had became “infinite”, this R code produced a (non-trivial) result:

> arthur[,1] [1] 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2

which shows that for N=21 and two green (2) tokens following a red (1) token, the procedure returns a configuration where all players have one and only one token. (Of course, the R code does not exclude the extreme case when all tokens are from a single colour.) From there, the generic solution follows: N must be a multiple of 3 and the tokens must be set as red-green-green-red-green-green-…

Filed under: Books, Kids, R Tagged: Le Monde, mathematical puzzle, R

**leave a comment**for the author, please follow the link and comment on their blog:

**Xi'an's Og » R**.

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.