Skip to content
Tyson Mao

Nim

An old game with a complete solution, and the solution is stranger than the game.

Counters are laid out in heaps — three of them here, holding three, five and seven. On your turn you take as many counters as you like, from a single heap, and at least one. Whoever takes the very last counter wins.

Don't Say 21 is this game with one heap, where the trick was to leave your opponent on a multiple of three. With one heap the answer is arithmetic you could work out on a walk. With three heaps that approach collapses immediately: there is no single number left to be a multiple of.

And yet it is solved — not approximately, not usually, but completely. From any position you can say who wins and exactly what they should do. The method involves writing the heap sizes in binary, which is not a thing that ought to have anything to do with taking counters off a table.

Part one

Three, five, seven

Three heaps. On your turn you take as many counters as you like — but from one heap only, and at least one. Whoever takes the last counter anywhere wins.

You move first, against a computer that plays perfectly. That sounds hopeless and is not: this position is a first-player win. There is exactly one right opening move, and after it you can never be beaten.

  1. heap 1
  2. heap 2
  3. heap 3

Take as many as you like from one heap. Whoever takes the last counter wins.