A game relevant to piles of coins.

algorithmscombinatorial-game-theorydynamic programminggame theory

There are $N$ piles of coins, the number of coins of a pile is $p_i(1\le i\le N)$. ($N$ is a prime number and $2\le N\le 30$).

A always plays first. A and B move in alternating turns. During each turn, the current player performs either of the following two moves:

  • Choose one pile and and remove $k(k>0)$ coins from it.

  • Remove $k$ coins from all $N$ piles, where $1\le k\le min(p_1,p_2,…,p_N)$. This move becomes unavailable if any pile is empty. I

Player who make the last turn will be the winner.

For examples:

  • With $n=2$ and $p_1=1,p_2=2$. The result is B.

  • With $n=3$ and $p_1=2,p_2=2,p_3=3$. The result is A.

I think this problem is relevant to Nim's game, this is my try:

  • Each turn of player X, X will remove $1$ coin from all $N$ piles until $X$ can't do it.(X is either A or B)
  • Next, we will consider the parity of the number of coins in remain piles to determine who is the winner, but I can't come to finally solution.

Best Answer

For $\ N=2\ $ it's fairly easy to tabulate the losing positions for the first player (i.e. $\ \mathcal{P}$-positions, or "safe" positions, according to the standard terminology), although I haven't found any simple expression for them. The first few are $\ \left\{1,2\right\}$, $\left\{3,5\right\}$, $\left\{4,7\right\}$, $\left\{6,10\right\},\ $ and so on.

It follows from this that simply removing one coin from both piles is not usually a good strategy. The position $\ \left\{5,7\right\}\ $, for instance is an $\ \mathcal{N}$-position in which the only winning moves are to take either $2$ coins from both piles, or $4$ coins from the pile of $7$, in both cases leaving one's opponent with the $\ \mathcal{P}$-position, $\left\{3,5\right\}\ $. Taking one coin from both piles, on the other hand, leaves one's opponent with the $\ \mathcal{N}$-position,$\ \left\{2,6\right\}\ $, from which he or she can win by taking $5$ coins from the pile of $6$.

The list, $\ \left\{a_1,b_1\right\}, \left\{a_2,b_2\right\},\dots, \left\{a_i,b_i\right\}, \dots, \ $ of $\ \mathcal{P}$-positions is constructed recursively as follows:

  1. $\ a_1=1\ $, $b_1=2\ $.
  2. Given $A_n=\left\{a_1, a_2, \dots, a_n\right\}\ $ and $B_n=\left\{b_1, b_2, \dots, b_n\right\}\ $, define \begin{eqnarray} a_{n+1} &=& \min\mathbb{N}^+\setminus\left(A_n\cup B_n\right)\ , \mbox{and}\ .\\ b_{n+1}&=&a_{n+1}+n+1\end{eqnarray}

If we put $\ P_n=\left\{\left\{a_i,b_i\right\}\left|i=1,2,\dots,n\right.\right\}\ $ then it's easy to demonstrate that:

  1. $\bigcup_\limits{i=1}^\infty A_i \cap\ \bigcup_\limits{i=1}^\infty B_i=\emptyset\ $,
  2. $\bigcup_\limits{i=1}^\infty A_i \cup\ \bigcup_\limits{i=1}^\infty B_i=\mathbb{N}^+\ $, and
  3. $\left\vert b-a\right\vert \le n\ \ \mbox{ for all }\ \ \left\{a,b\right\}\in P_n\ $

We can now show by induction that the set of $\ \mathcal{P}$-positions is $\ P=\bigcup_{i=1}^\infty P_i\ $.

First, let $\ \left\{a,b\right\}\not\in\ P\ $, with $\ a\le b\ $. If $\ a=b\ $, then the first player can win immediately by taking all the coins from both piles. Otherwise, if $\ r= b-a\ $, then either $\ a=a_k\ $ or $\ a=b_k\ $ for some $\ k\ $. In the first case, since $\ \left\{a,b\right\}\not\in\ P_r\ $, we must have $\ a> a_r\ $, and the first player can leave the second with the position $\ \left\{a_r,b_r\right\}\in P_r\ $ by removing $\ a-a_r\ $ coins from both piles. In the second case, the first player can leave the second with the position $\ \left\{a_k,b_k\right\}\in P_k\ $, again with $\ a_k < a\ $, by removing $\ b-a+k=b-a_k\ $ from the pile of $\ b\ $. In position $\ \left\{1,2\right\}\ $ there are only four moves possible for the first player:

  1. Take one coin from each pile. The second player can then win by taking the one remaining coin;
  2. Take the coin from the pile of one. The second player can then win by taking both coins from the remaining pile;
  3. Take one coin from the pile of $2$. The second player can then win by taking both of the remaining coins;
  4. Take both coins from the pile of $2$. The second player can then win by taking the single remaining coin.

Thus, the position $\ \left\{1,2\right\}\ $ is a $\ \mathcal{P}$-position. Suppose now that all positions in $\ P_{n-1}\ $ are $\ \mathcal{P}$-positions, and consider the position $\ \left\{a_n,b_n\right\}\ $. If the first player takes all the coins from either pile, then the second player wins immediately by taking all the coins from the other. If he or she takes $\ c < a_n\ $ coins from the $\ a_n\ $ pile, then the new position, $\ \left\{a_n-c,b_n\right\}\ $, cannot be in $\ P\ $, because $\ b_n-\left(a_n-c\right)=n+c\ $ but $\ a_n-c< a_{n+c}\ $. If he or she takes $\ c \le n\ $ coins from the pile of $\ b_n\ $, the new position, $\ \left\{a_n,b_n-c\right\}\ $ again cannot be in $\ P\ $, because $\ b_n-c-a_n = n-c\ $, and either $\ n-c=0\ $, or $a_n \ne a_{n-c}\ $. If he or she takes $\ c\ $ coins from the $\ b_n\ $ pile, with $ n<c< b_n\ $, then the new position, $\ \left\{b_n-c, a_n\right\}\ $ cannot be in $\ P\ $, because $\ a_n\notin B\ $. Finally, if the first payer takes $\ c\ $ coins from both piles, the new position, $\ \left\{a_n-c,b_n-c\right\}\ $ cannot be in $\ P\ $ because $\ b_n-c-\left(a_n-c\right)=n\ $, and $\ a_n-c < a_n\ $. Thus, from the argument above, whatever the first player does, the second player can either win immediately, or move the position to $\ \left\{a_k, b_k\right\}\in P_k\ $ with $\ k < n\ $, which is a $\ \mathcal{P}$-position by the induction hypothesis. Thus $\ \left\{a_n, b_n\right\}\ $ is a $\ \mathcal{P}$-position, and it follows by induction that all positions in $\ P\ $ are $\ \mathcal{P}$-positions.

On the other hand, the argument above shows that a player faced with a position not in $\ P\ $ can always either win immediately, or move the game to a $\ \mathcal{P}$-position in $\ P\ $, so a position is a $\ \mathcal{P}$-position, if and only if it is in $\ P\ $.

Addendum: I have just become aware that the $2$-pile version of this game is known as Whytoff's game, its solution having already been given by the Dutch mathematician Willem Whytoff in 1907.

Related Question