Back

Answers to Nim

How can you win with three piles? Does one of the players have a winning strategy? Which player?

The important thing is to think of the number of objects in each pile in binary. That is, if the pile has 7 objects, we represent that as

111 (1x4 + 1x2 + 1x1)

or if we have 13 objects, we represent it as

1101 (1x8 + 1x4 + 0x2 + 1x1).

Now in order to set up a matching situation, we want to consider the sets of size 2k represented by the binary notation in pairs. If we start with piles of 7, 13 and 9 objects, we write this in binary as 111, 1101, and 1001. This means there are two sets of 8, two sets of 4, one set of 2, and three sets of 1. Therefore, in order to get things matched up, we need to take away the set of 2 and one of the sets of 1. We can do this by taking away 3 objects from the pile of 7. Now we are left with piles of 4, 13, and 9. Whatever the other player takes away we match. This does not mean taking away the same number, but always checking the sets of size 2k.

If the other player removes 5 from the pile of 13, we are left with piles of 4, 8, and 9, written in binary as 100, 1000, and 1001. There are then two sets of 8, one of 4, and one of 1. So we need to remove the set of 4 and the set of 1. However, this time we will have to work harder to do this -- there is no way we can remove the set of 4 and set of 1 from the same pile! Therefore, we will have to break up one of the sets of 2k. We can do this by breaking up the set of 4 and leaving a set of 1 to match the other set of one. That is, we can remove 3 from the pile of 4 leaving piles of 1, 8, and 9 (in binary 1, 1000, 1001).

So why can we always keep things matched? It is easy if we can take away the sets from the same pile like we did the first time. If this isn't possible, we can break up the biggest extra set and will have enough to leave all the other sets of 2k we need to match things!

Since we can always match things up, we know that we will win. Since by working in binary we are sure that there are two sets of powers of 2 that match exactly -- and two sets of 2k don't come from the same pile! We know that the other player can't take away two of our sets and leave it still matched. Since at the end, there are no piles of anything, i.e. the sets of powers of 2 match, we know we are the player that will make this happen -- and we will win!

Which player has a winning strategy depends on whether the piles come with matching numbers of sets of 2k. If it does, the second player has the winning strategy since the first player must disturb the matching. Otherwise, the first player can make the sets of size 2k match, and can go on to win.