What's new

A game of Nim

By David, 24 December 2013 Activity

You will need

Several black tokens on a table.

This game is easier if you can count the tokens clearly.

  • Some tokens
  • A friend to play with

What to do

  1. Put some tokens in a pile (around 12 will do to start).
  2. Decide who is going first.
  3. The first player must take either one or two tokens from the pile.
  4. The second player must then take one or two tokens from the pile.
  5. Keep alternating turns until the last tokens is taken. The person who takes the last token is the loser.
    Several black tokens. Someone is taking two of them away.

    On your turn, you can take either one or two tokens.


Can you come up with a strategy that always wins? What if you start with a different number of tokens?

What’s happening?

To work out how to win, it helps to work backwards. If it’s your turn and there’s only one token left, then you lose. This means that if it’s your turn and there are two or three tokens left, you should leave your opponent with one.

What if there are four tokens on your turn? If you take one, then your opponent will take two, and you lose. If you take two, then your opponent can take one, and you’ll lose. So if you can, you should try to give your opponent a pile of four tokens on their turn. Using this strategy, you should be able to win if there are five or six tokens in the pile at the start of your turn.

A single token on a table. Someone is reaching for it.

Whoever takes the last token loses.

You can extend this sort of strategy as far as you want. In order to win, you should always give your opponent a number of tokens that is a multiple of three, plus one more. Then, if they take away one, you take two, and if they take away two, you take one. This guarantees they will always receive a pile with one more than a multiple of three tokens. Eventually, you will give your opponent seven counters, and then four counters, and finally one counter.

Applications

Nim is a very special game because it has a strategy that will always win, no matter what. Most games don’t have a definite winning strategy. There are several reasons why Nim is like this.

Firstly, there are no random parts to the game. You never roll dice, or draw cards – the only things that matter are what you and your opponent do. Secondly, there’s no way to have a tied game, so one of the players is going to win. Thirdly, the game has to end after a certain number of turns. Some games can get caught in a loop so that they never end, but Nim can’t have more goes than there are tokens at the start. Finally, it is also a two player game. If you have three or more players, then the result can depend on how nice the other players are to you.

Any game that has all of these properties will have a definite winning strategy for one of the two players, although that strategy is not always easy to find. For example, the first player doesn’t always have the winning strategy. If you play Nim starting with seven tokens, the second player will win if they play correctly, and the first player can’t stop them.

More information

Play Nim online

A harder version of Nim

Nim on Wikipedia (more advanced)

Did you like this activity? Subscribe to Maths and Stats by Email!

1 comments

  1. I love this game, though I find it infuriating, as I’m pretty poor at strategy, lol

      Reply

Leave a Reply

By posting a comment you are agreeing to the Double Helix commenting guidelines.

This site uses Akismet to reduce spam. Learn how your comment data is processed.