Britannica Sources used in this answer

How does the game Nim work?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

Nim is an ancient mathematical game played by two people who take turns removing objects from several piles. In the standard version, a player may remove any number of objects (at least one) from a single pile, and the player who removes the final object wins.12

Strategy and Binary Logic

The game is defined by "safe" and "unsafe" positions. A position is considered safe if the player who just moved has secured a winning state; otherwise, it is unsafe. To determine the status of a position, players convert the number of objects in each pile into binary notation. If the sum of each binary column is zero or an even number, the position is safe. A skillful player aims to move so that every position they leave for their opponent is a safe one.12

Because this strategy relies on binary arithmetic, it is highly suitable for computers. In 1940, physicist Edward Uhler Condon showcased the Nimatron, a machine capable of playing a perfect game of Nim, at the New York World’s Fair.12