Nim
Quick Pitch
Nim is a pure strategy game where players take turns removing objects from heaps β the player who takes the last object wins (or loses, in the reverse version).
Hook
Nim looks deceptively simple: a few piles of stones, take some from one pile per turn, try to take the last one. But hidden underneath is a perfect mathematical solution β once you know the "Nim-sum" trick, you can beat any opponent who doesn't know it. Nim is the game where math gives you a genuine superpower.
Equipment Needed
- Objects to form heaps (stones, sticks, coins, tokens β typically 10β20 total)
- 3β4 heaps (common starting: 3, 4, 5 or 3, 5, 7)
- Flat surface (table, ground, etc.)
No objects? Draw the heaps on paper as rows of dots or tally marks, and cross them out instead of removing physical pieces. Works just as well and needs only a pencil.
Rules
Gameplay
- Players alternate turns
- On each turn, remove one or more objects from exactly one heap
- Choose which heap and how many objects to remove
- Cannot remove from multiple heaps in one turn
- Continue until all objects are removed
Win Condition
Normal play: Player who removes the last object(s) wins Misère: Player forced to take the last object(s) loses
Expert Player
Tips
Winning Strategy (Normal Play):
- Calculate the Nim-sum (XOR) of all heap sizes
- If Nim-sum = 0, position is losing (previous player should win)
- If Nim-sum β 0, move to create Nim-sum = 0
- Make the Nim-sum of all heaps equal to 0, then opponent will always face Nim-sum β 0
Example:
- Heaps (3, 5, 7): 3 XOR 5 XOR 7 = 1 (winning position)
- Remove 2 from heap of 7 to get (3, 5, 5): 3 XOR 5 XOR 5 = 3 (still winning)
- Remove 3 from heap of 3 to get (0, 5, 5): 0 XOR 5 XOR 5 = 0 (losing position for opponent)
Variations
Standard Nim
3-4-5 starting position is common.
Wythoff's Nim
Different starting position optimized for interesting play.
Misère Variant
Player taking the last object loses (changes strategy completely).
Modified Heap Removal
Variants limit how many can be removed per turn (e.g., maximum 3 objects).
Green Hackenbush
Graph-theoretic variant extending nim concepts.
Learn More β History & Origins
History & Origins
Nim is an ancient game with origins in East Asia, particularly China, where early versions were played centuries ago. The game was formalized mathematically in the early 20th century by mathematician C. L. Bouton, who developed the complete strategy using the Nim-sum (binary XOR) principle. The name "Nim" comes from the obsolete English word meaning "to steal" or "to take," giving the game its precise descriptive name.
Cultural Context
Nim has a remarkable dual life: as a children's game simple enough to play with pebbles, and as a foundational object of study in combinatorial game theory. The complete mathematical solution published by Bouton in 1901 made Nim one of the first games to be "solved" β meaning there is a provably optimal strategy that guarantees a win from certain positions. This made it a natural teaching tool in mathematics and computer science, where it appears in curricula about binary arithmetic, game trees, and decision theory.
Nim was also among the first games to be implemented on a computer. In 1951, a machine called Nimrod was built specifically to play Nim at the Festival of Britain β an early demonstration that computers could play games, predating chess-playing computers by years. The game's mathematical tractability has kept it relevant in academic contexts long after most games of similar vintage have been forgotten. Nim also became the cornerstone example in combinatorial game theory when John Conway, Elwyn Berlekamp, and Richard Guy published "Winning Ways for Your Mathematical Plays" (1982), establishing that the Nim-sum analysis generalizes to an enormous family of impartial games β making Nim not just a solved game but the key to solving many others.
See Also
Equipment
Objects
Any identical objects:
- Stones or pebbles (traditional)
- Sticks or matches
- Coins or tokens
- Beans or seeds
Setup
Arrange objects into heaps. Standard starting position (Wythoff's Nim):
- Heap 1: 3 objects
- Heap 2: 4 objects
- Heap 3: 5 objects
Or any arrangement decided by players.
Strategy: Mathematical Analysis
Nim is completely solved by the Nim-Sum principle:
Nim-Sum: Calculate the XOR (binary exclusive-or) of all heap sizes. A position is:
- Winning for the player to move: If nim-sum is non-zero
- Losing for the player to move: If nim-sum is zero
Optimal play: Always move to create a zero nim-sum for opponent.
Example Analysis
Starting position (3, 4, 5):
- 3 = 011β
- 4 = 100β
- 5 = 101β
- XOR = 010β = 2 (non-zero, winning position)
To win, move to zero nim-sum. Possible moves:
- Remove from 5, leaving 1: (3, 4, 1)
- 3 XOR 4 XOR 1 = 011 XOR 100 XOR 001 = 110 (not zero)
- Remove from 5, leaving 0: (3, 4)
- 3 XOR 4 = 011 XOR 100 = 111 (not zero)
- Remove from 4, leaving 0: (3, 5)
- 3 XOR 5 = 011 XOR 101 = 110 (not zero)
- Remove from 3, leaving 1: (1, 4, 5)
- 1 XOR 4 XOR 5 = 001 XOR 100 XOR 101 = 000 (zero! winning move)
This demonstrates that mathematical analysis completely determines optimal play.