Auto-Nim

Two robots play a simplified version of Nim with one pile of x x coins. They alternate turns, and every turn, if there are a a remaining coins, one of the robots takes between 1 1 and a a coins (inclusive) at random with equal probability. The game ends when a robot takes all of the remaining coins. Let E ( x ) E(x) denote the expected number of turns it would take for the robots the finish a game with a pile of x x coins. Find the minimum value of x x such that E ( x ) > 10 E(x)>10 . You are allowed to use a computer program.

Bonus : Prove that for x 2 x≥2 , the probability that one of the robots wins is 0.5 0.5 no matter whether it goes first or second.


The answer is 12367.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Sam Zhou
Sep 1, 2019

We can set up a recurrence relation to solve the problem.

It is clear that E ( 1 ) = 1 E(1)=1 .

If there are m m coins, a robot can take any number of coins from 1 1 to m m , all with a probability of 1 m \frac{1}{m} . Therefore, the probability that there are n n remaining coins, where n Z , 0 n m 1 n\in\mathbb{Z},0≤n≤m-1 , is 1 m \frac{1}{m} .

We can deduce that E ( m ) = 1 + 1 m i = 0 m 1 E ( i ) E(m)=1+\frac{1}{m}\sum_{i=0}^{m-1} E(i) . Note that 1 1 is added because the action of a robot taking any number of coins between 1 1 and m m counts as one turn. Since E ( 0 ) = 0 E(0)=0 , we can write the above expression as E ( m ) = 1 + 1 m i = 1 m 1 E ( i ) E(m)=1+\frac{1}{m}\sum_{i=1}^{m-1} E(i) , or E ( m ) = 1 + 1 m E ( m 1 ) + 1 m i = 0 m 2 E ( i ) E(m)=1+\frac{1}{m}E(m-1)+\frac{1}{m}\sum_{i=0}^{m-2} E(i) .

Notice that E ( m 1 ) 1 = 1 m 1 i = 0 m 2 E ( i ) E(m-1)-1=\frac{1}{m-1}\sum_{i=0}^{m-2} E(i) . We can use this to simplify the above expression as E ( m ) = 1 + 1 m E ( m 1 ) + m 1 m ( E ( m 1 ) 1 ) E(m)=1+\frac{1}{m}E(m-1)+\frac{m-1}{m}(E(m-1)-1) .

Therefore, E ( m ) = 1 + 1 m E ( m 1 ) + m 1 m ( E ( m 1 ) 1 ) = 1 + 1 m E ( m 1 ) + m 1 m E ( m 1 ) m 1 m = E ( m 1 ) + 1 m E(m)=1+\frac{1}{m}E(m-1)+\frac{m-1}{m}(E(m-1)-1)=1+\frac{1}{m}E(m-1)+\frac{m-1}{m}E(m-1)-\frac{m-1}{m}=E(m-1)+\frac{1}{m} .

Because E ( 1 ) = 1 E(1)=1 , we can deduce that E ( m ) = i = 1 m 1 i E(m)=\sum_{i=1}^{m}\frac{1}{i} . Then a simple computer program can show that minimum value of x x such that E ( x ) > 10 E(x)>10 is 12367 \boxed{12367} .

Please post your solution to the bonus problem if you figured it out!

Mark Hennings
Sep 1, 2019

Conditional expectation theory tells us that E ( x ) = 1 + 1 x j = 1 x E ( x j ) x 1 E(x) \; = \; 1 + \frac{1}{x}\sum_{j=1}^x E(x-j) \hspace{1cm} x \ge 1 where we are defining E ( 0 ) = 0 E(0)=0 . Let us consider the generating function of these coefficients E ( t ) = x = 1 E ( x ) t x \mathcal{E}(t) \; =\; \sum_{x=1}^\infty E(x)t^x Then t E ( t ) = x = 1 x E ( x ) t x = x = 1 ( x + j = 1 x E ( x j ) ) t x = x = 1 ( x E ( x ) + j = 0 x E ( x j ) ) t x = x = 1 x t x E ( t ) + 1 1 t E ( t ) = t ( 1 t ) 2 + t 1 t E ( t ) d d t ( ( 1 t ) E ( t ) ) = ( 1 t ) E ( t ) E ( t ) = 1 1 t ( 1 t ) E ( t ) = ln ( 1 t ) E ( t ) = ln ( 1 t ) 1 t \begin{aligned} t\mathcal{E}'(t) & = \; \sum_{x=1}^\infty xE(x)t^x \; = \; \sum_{x=1}^\infty\left(x + \sum_{j=1}^x E(x-j)\right)t^x \; = \; \sum_{x=1}^\infty\left(x - E(x) + \sum_{j=0}^x E(x-j)\right)t^x \\ & = \; \sum_{x=1}^\infty xt^x - \mathcal{E}(t) + \frac{1}{1-t}\mathcal{E}(t) \; = \; \frac{t}{(1-t)^2} + \frac{t}{1-t}\mathcal{E}(t) \\ \frac{d}{dt}\Big((1-t)\mathcal{E}(t)\Big) & = \; (1-t)\mathcal{E}'(t) - \mathcal{E}(t) \; = \; \frac{1}{1-t} \\ (1-t)\mathcal{E}(t) & = \; -\ln(1-t) \\ \mathcal{E}(t) & = \; -\frac{\ln(1-t)}{1-t} \end{aligned} so we end up with the Harmonic numbers E ( x ) = H x x 0 E(x) \; = \; H_x \hspace{2cm} x \ge 0 Since H x ln x + γ H_x \sim \ln x + \gamma as x x \to \infty we deduce that H x 10 H_x \approx 10 when x e 10 γ = 12366.96811 x \approx e^{10 - \gamma} = 12366.96811 , which gives us a good point to start calculating. Since H 12367 = 10.000043 H_{12367} = 10.000043 and H 12366 = 9.999162 H_{12366} = 9.999162 , we obtain the answer 12367 \boxed{12367}


As for the bonus question, let a x a_x be the probability that the first robot A wins, given that it is robot A's turn and there are x x coins in the pile, and let b x b_x be the probability that the first robot A wins, given that it is the second robot B's turn and there are x x coins in the pile. Then it is easy to see that we have the recurrence relations a x = 1 x j = 1 x 1 b x j + 1 x b x = 1 x j = 1 x 1 a x j \begin{aligned} a_x & = \; \frac{1}{x}\sum_{j=1}^{x-1}b_{x-j} + \frac{1}{x} \\ b_x & = \; \frac{1}{x}\sum_{j=1}^{x-1}a_{x-j} \end{aligned} together with a 1 = 1 a_1=1 and b 0 = 0 b_0=0 . It is easy to check that these recurrence relations (plus initial conditions) define all the probabilities a x , b x a_x,b_x , and that they are satisfied by a x = { 1 x = 1 1 2 x 2 b x = { 0 x = 1 1 2 x 2 a_x \; = \; \left\{ \begin{array}{lll} 1 & \hspace{1cm} & x = 1 \\ \tfrac12 & & x \ge 2 \end{array}\right. \hspace{2cm} b_x \; = \; \left\{ \begin{array}{lll} 0 & \hspace{1cm} & x = 1 \\ \tfrac12 & & x \ge 2 \end{array}\right. which gives us the required result.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...