NIM

A deterministic game

The game of nimm, nimb or nim (I am not sure of the correct name in English) is a game usually played with match sticks or pebles as a seemingly equalitarian strategy game between two players. The players take turns in chosing a heap and taking at least one item out of the game. There are no unknowns such as dice throws or shuffled card decks.

In addition, there are only a fixed and limited number of items, a limited set of possible final moves, and only one of two outcomes; you win or you lose.

It is therefore possible for players with some experience to memorize all possible steps from start to finish, and win without effort in practically every match.

On top of that, the mathematical theory needed in order to play safely and deterministically, and assure a win when you have the initial advantage, is well known and easily programmed into a short computer program; just check the javascript logic of the game on this page (The version of the game here uses 16 identical items in 4 heaps of repectively 1, 3, 5,and 7 items, and the player that manages to take the last item wins).

A disturbing game

Yet, almost everyone is deeply disturbed as they try the game up against an expert player. They notice a big mismatch between the extreemely equalitarian and fair rules for the game, and the complete supremacy that the opposition enjoys.

The mathematical logic needed in order to check the safeness of a position involves an Exclusive or (XOR) operation between the binary representations of numbers of game assets in remaining heaps. It is therefore very difficult to apply or think procedurally about the move during the quick pace in which the game is usually played at.

Luckily, it takes a few dozen games to start noticing the winning patterns.

It can be a very entertaining activity during the initial period of surprise, amazement and incredulous requests to play again and again. It can also serve as a good illustration of the necessity of knowledge and mastery when failure must not be risked, however remote the probability of loss may seem initially.

Almost magical, yet barely mechanical

It is easy to see that the nim game is much more like an illusionists trick, and much less like a game of "Go" or a game of "Chess".

You can try playing a javascript version of this game against your browser by clicking here. Enjoy!

You can also play it offline after the page is loaded, or if you save this page and its logic (index.htm, nim.js, item.gif and index_noscript.htm) on local storage, you may load it from there when offline.