A game problem- double or increment by 1

792 Views Asked by At

Its a two player game. Initially $P=1$, and there is some fixed integer $Q>1$.

A valid move consists of either increasing $P$ by $1$ or doubling it iff on doing so $P$ does NOT exceed $Q$.
The players move alternatively. The game ends when $P=Q$. The loser is the player who cannot make a move. The task is to predict the winner.

My analysis so far: The second player can always force his opponents move to end on an even number. Hence if $Q$ is odd the second player can definitely win. However I am not able to analyse the game when $Q$ is even. Some hints please? Thank you.

1

There are 1 best solutions below

0
On

The answer has been lying hidden in plain sight in Greg's first comment: For even $Q$, the game can be reduced to the game for $\left\lfloor\frac Q4\right\rfloor$. The first player to exceed this limit loses, since the other player immediately doubles to an even number that can no longer be doubled and wins when the increments reach $Q$. Thus, the player who wins the game for $\left\lfloor\frac Q4\right\rfloor$ wins the game for $Q$. The operation $\left\lfloor\frac Q4\right\rfloor$ is a right-shift by two bits (discarding the least significant two bits). It follows that the game is a win for player II if and only if the binary representation of $Q$ contains a $1$ in an even-numbered bit (with the least significant bit numbered $0$).