Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

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.

Related

To leave a comment for the author, please follow the link and comment on their blog: R – Xi'an's Og.