Nim
Heaps of counters; take any number from one heap; whoever takes the last wins. Pick the winning move — or see that there is none — by the XOR rule.
How it plays
Two players take turns. On a turn you take as many counters as you like, at least one, from a single heap. Whoever takes the last counter wins. Choose the move that wins whatever the other player does, or “no winning move” if every move loses to perfect play.
The rule (Bouton, 1901): write each heap in binary and XOR them — for each column, 1 if it has an odd number of 1s. If the result, the nim-sum, is 0, the player to move loses. Otherwise, find a heap that gets smaller when XORed with the nim-sum, and shrink it to that.
Levels add heaps and make them bigger without end. The working shows the binary.
Keys
Space starts and skips ahead · 1–9 pick · Enter submits · Esc stops. On a phone, tap.
What it trains
This practises the nim-sum rule and binary XOR in your head, and the idea that a game can be solved. It claims nothing wider.
Learn
How to get better at nim: the method, the techniques, what each new level asks of you, and the traps the wrong answers are made of.
Your approach to each question
- Ignore the options at first. Break every heap into powers of two — 8, 4, 2, 1 — and note which of them each heap holds.
- Cross off the powers in pairs. Whatever is left over, added up, is the nim-sum.
- If nothing is left, the nim-sum is 0: you are already lost against perfect play, so pick “No winning move”.
- If something is left, find a heap that holds the biggest leftover power. Flip that heap’s leftover powers — remove the ones it has, add the ones it lacks — and the new size is what you shrink it to.
- Check the one option that names that heap and that amount. If your arithmetic and the option disagree, apply each option in turn and see which leaves a nim-sum of 0.
Techniques and tricks
Cancel powers of two in pairs
XOR is “keep a power when it appears an odd number of times”. Split each heap into 8s, 4s, 2s and 1s and strike out matching pairs; you never have to write binary.
e.g. 13, 10, 7, 1, 1: 13 = 8+4+1, 10 = 8+2, 7 = 4+2+1. Two 8s, two 4s, two 2s, four 1s — all cancel, so the nim-sum is 0.
Equal heaps vanish
Two heaps of the same size cancel completely, whatever the size. Strike them out first and work only on what is left.
e.g. 9, 9, 4, 5: the 9s cancel; 4 XOR 5 = 1.
Two heaps: make them equal
With two heaps the nim-sum is 0 exactly when they are equal. So the winning move is to cut the bigger one down to the smaller; if they are already equal, there is none.
e.g. 7 and 4: take 3 from the 7.
Know the zero triples
Some three-heap positions come up again and again and are lost for the player to move. Learn them by sight: 1-2-3, 1-4-5, 2-4-6, 3-4-7, 3-5-6, 1-6-7, 2-5-7.
e.g. 3, 5, 6 has nim-sum 0 — no winning move.
Shrink the heap with the top bit
Only a heap that holds the nim-sum’s biggest power can be shrunk to fix it. XOR that heap with the nim-sum; the result is smaller, and the difference is how many to take.
e.g. 6, 9, 12: nim-sum 3, top power 2. Only 6 holds a 2. 6 XOR 3 = 5, so take 1 from that heap, leaving 5, 9, 12.
Test the options backwards
With only a few options shown, apply each move and compute the new nim-sum. Exactly one leaves 0, or none does and the answer is “No winning move”.
As the levels climb
- You start with two heaps of up to 3, where the winning move is simply to make the heaps equal.
- Then a heap is added, then the heaps grow by two, in turn, until you reach the “Most heaps” setting. With three heaps or more, the equal-heaps shortcut stops working on its own; pair off what you can, then do the powers of two.
- Once the heap count is capped, only the sizes climb, by two a level, without end. Past 7 a heap needs an 8 in its breakdown, past 15 a 16. Say each heap as its powers aloud — “thirteen is eight, four, one” — before cancelling.
Traps to avoid
- “No winning move” is offered even when there is one. Choose it only when the nim-sum is truly 0, never because the position looks even.
- Clearing the biggest heap feels strong and is offered as a lure. Taking a whole heap is right only when the other heaps already cancel to 0 between them.
- Levelling the two biggest heaps wins only when the rest cancel out. With three heaps or more, check the leftovers before you copy the two-heap trick.
- Taking a single counter, or emptying the smallest heap, are timid moves offered as lures. Check them like any other move: they win only if they leave a nim-sum of 0.
- Shrinking the wrong heap: XOR a heap that lacks the top power and it grows, which is not a legal move. If the new size comes out bigger, you picked the wrong heap.
How to practise
- Set “Most heaps” to 3 until the zero triples are automatic, then raise it towards 6.
- Turn “Options shown” up to 8 so testing every option backwards is too slow, and you have to compute the move directly.
- Keep “Feedback” on Instant at first and read the binary in the working after a miss; it shows exactly which column you mis-counted.
- Once you are reliable, set “Time pressure” to Normal: the clock gives 20 seconds plus 5 for each heap.
Levels
It is untimed unless you turn the clock on. There is no last level: at least one dial turns without end. Your level is judged on your last ten answers, every ten: 90% moves you up, below 80% moves you down, which holds most people near four in five right.
All of it is in the settings beside Start — how many answers a judgement looks at and how often it recalibrates, the thresholds, the time, which questions, how many options, and whether you see each verdict at once or review them together at the judgement. You can also jump to any level.
More logic
All games →Tower of Hanoi
How many moves does a Tower of Hanoi of n disks take? Derive 2ⁿ − 1, then count from a position part-way through, and with neighbouring pegs only.Find the fake coin
Twelve coins, one fake, a balance: how many weighings, at worst? Derive the base-3 bounds for a heavier coin and for one that may be either.Water jugs
A 3-litre jug, a 5-litre jug and a tap: can you measure exactly 4 litres, and in how few steps? Decide by the gcd rule; count by the shortest route.Trap questions
Bat-and-ball questions with fresh numbers every time: the first answer that comes to mind is wrong. Catch it, then work it out.Codebreaker
Deduce a hidden code from ● and ○ clues. Each turn, pick the guess that fits every clue so far. Longer codes and more letters, without end.Higher or lower
Find a hidden number from what each guess says: higher or lower. Halve what is left each time and you never need more than log₂ guesses.