[This article was first published on 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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
A simple 2×2 Le Monde mathematical puzzle:
Arielle and Brandwein play a game out of two distinct even integers between 1500 and 2500, and y. Providing one another with either the pair (x/2,y+x/2) or the pair (x+y/2,y/2) until they run out of even possibilities or exceed 6 rounds. When x=2304, what is the value of y that makes Brandwein win?
Which I solved by a recursive function (under the constraint of a maximum of 11 levels of recursion):
nezt=function(x,y,i=1){ if ((i>11)||((is.odd(x)&is.odd(y)))){ return(-1) }else{ z=-1 if (is.even(x)) z=-nezt(x/2,y+x/2,i+1) if (is.even(y)) z=max(z,-nezt(y/2,x+y/2,i+1)) return(z)}}
and checking all values of y between 1500 and 2500 when x=2304, which produces y=1792 as the only value when Arielle loses. The reason behind (?) is that both 2304 and 1792 are divisible by 2⁸, which means no strategy avoids reaching stalemate after 8 steps, when it is Arielle’s turn to play.
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.