Multiple stacks of coins, take turns removing either one or all from any of the stacks, who will get the last turn, A or B?

1.1k Views Asked by At

this is a variation of the coin pile removing game that I have seen in various places online. In this case the properties are as such:

There are n stacks of coins all potentially different sizes. Starting with Player A, the players A and B take turns removing either one or all the coins from one of the stacks. The person left with no turn possible loses. How would I go about solving this problem?

2

There are 2 best solutions below

0
On BEST ANSWER

Prompted by Théophile's answer, we can make a direct statement of how to play the game. We claim the $P$ positions, won by the previous player, are those that have an even number of piles with an even number of stones and an even number of piles that have an odd number of stones, and the $N$ positions are the rest. To prove this we need to show that the terminal position is $P$, that all moves from $P$ positions result in $N$ positions, and that every $N$ position has at least one move to a $P$ position. The terminal position has no piles, so has an even number of piles of each parity. From a $P$ position, any move will leave an odd number of piles of the parity moved in. If the move leaves stones in the pile moved in, it will also leave an odd number of piles of the other parity, but we don't need that. If there are an odd number of piles of one parity and an even number of the other, take an entire pile of the parity with an odd number of piles and this will leave a $P$ position. If there are an odd number of piles of each parity, take one stone from a pile with an even number of stones and this will leave a $P$ position. This shows the $N$ and $P$ positions are as claimed and gives a specific move where there is a winning one (the $N$ positions).

13
On

This game is similar to Nim and can be solved using the Sprague-Grundy theorem.

We can calculate the Nim-values of the stacks in your game by looking at the choices available and finding the minimal excluded element, or mex.

Let $v(n)$ be the Nim-value of a stack of size $n$. Then:

  • A pile of size $1$ can only be reduced to $0$; $v(1) = mex(\{0\})=*$.
  • A pile of size $2$ can be reduced to $0$ or $1$; $v(2) = mex(\{0,v(1)\})=*2$.
  • A pile of size $3$ can be reduced to $0$ or $2$; $v(3) = mex(\{0,v(2)\})=*$.
  • A pile of size $4$ can be reduced to $0$ or $3$; $v(4) = mex(\{0,v(3)\})=*2$.
  • $\ldots$

In short, we can look at each pile as being either empty, even, or odd.