← The collection

Nim.

Take stones from one pile and try to take the last stone.

Interactive experimentintuitiveField note ·
Preparing the experiment…
THE SHORT VERSION

Nim, explained.

Nim is a two-player game of removing objects from piles, with a complete strategy for the normal rule in which taking the last object wins.

01 / THE MECHANISM

Why it happens

A move changes only one pile. The bitwise XOR of pile sizes identifies balanced positions: from a nonzero nim-sum, a legal move can make it zero, while any legal move from zero makes it nonzero.

Normal-play Nim has positions from which a perfect opponent can force a win. The XOR, or nim-sum, identifies the balanced positions.

Read the result

Watch the remaining pile sizes after the bot responds. It makes the nim-sum zero whenever possible. Try a different opening after Reset and compare the positions you leave, rather than only how many stones you take.

02 / FOLLOW IT THROUGH

A worked example

A winning opening

  1. Piles 3, 4 and 5 have nim-sum 3 XOR 4 XOR 5 = 2.

  2. Removing two from the first pile leaves 1, 4 and 5, whose XOR is zero.

  3. Against perfect replies, preserving that balanced position after your moves gives a route to taking the last stone.

OPTIONAL DEEPER DETAILGo deeper: inside the model

Inside this model

The bot removes stones to make the nim-sum zero when possible, otherwise takes one stone. Both players use the same legal moves and the normal last-stone-wins rule.

03 / BEYOND THE EXPERIMENT

Where this idea is useful

A practical use

A visible move can be evaluated by the future options it leaves, rather than only by its immediate size.

CHECK YOUR INTUITION

A common misconception

THE TEMPTING CONCLUSION

“Taking the largest number of stones is always best.”

THE MORE USEFUL DISTINCTION

The structure of the remaining piles matters. A smaller removal can leave the opponent a losing position.

What this explanation leaves out

  • This is normal-play Nim. Changing the last-stone rule changes the strategy; the bot plays optimally.
ONE MORE QUESTION

Does this strategy also apply when taking the last stone loses?

Not unchanged. That misère variant needs different treatment near the end of the game.

TAKE THE IDEA WITH YOU

Can you identify a move that improves your future position without maximizing the immediate gain?

Associated thinkers

Further reading

Explore the original research or the teaching reference behind this experiment.