Nim & Grundy Numbers
Nim is the fruit fly of game theory: take any number of stones from one heap, last stone wins. Behind it hides a stunning theorem — a position is losing exactly when the XOR of the heap sizes is zero. Play against the computer, which plays the perfect XOR strategy, and watch the binary analysis panel show the nim-sum after every move. Once you see it, you can win Nim against anyone — if the nim-sum lets you.
Runs 100% in your browser — simulations are computed locally on your device.
Read the full guide to this tool
Notes
- Winning strategy: always move to make the XOR of heap sizes zero.
- If the nim-sum is already zero, every move loses against perfect play — good luck.
- Sprague–Grundy: every impartial game is equivalent to some Nim heap — Nim is universal.
- Runs 100% in your browser — simulations are computed locally on your device.