# Nim

The classic Nim game consists of three piles or rows of three, four and five matches. Both players have to take it in turns to take at least one match from one of the piles. The player who takes the last match is the winner. Pebbles, coins or any other objects can be used instead of matches.

Numerous variations on the number of piles and objects exist. There is also the rule that the player who takes the final object loses.

## Nim – history

The origin of the game is uncertain. Similar games are known to have existed in ancient China. The earliest reference to the game in Europe dates back to the early sixteenth century. The etymology of the name is also unclear. According to one possible explanation, it is derived from the Old English or German "nim" (take).

## Nim – mathematics

The theory of Nim harks back to Harvard mathematics professor Charles Leonard Bouton (1902). His solution for any number of piles and objects is based on the binary representation of all the numbers. The number of objects in each pile is written as the sum of powers of two. The situation is then favourable for a player if he or she can take so many objects from a pile that there is no power of two in an odd number overall after the move. Otherwise, the situation is unfavourable. This gives rise to the game’s solution for any starting situation. In the classic version of the game, the first player always wins with the right strategy.

As the theory of Nim uses the binary system, it is unsurprising that it was also applied in the first digital computers. Nimatron was presented at the 1939–1940 New York World Fair: a computer which played Nim flawlessly.