Three piles of stones. Two players alternate; each turn, remove any number of stones from one pile. The player who takes the last stone wins. Click stones to remove them — the computer plays the optimal response. The XOR of pile sizes (the nim-sum) tells you everything. Sprague-Grundy 1935: this analysis extends to every impartial game.
Your turn — click stones to remove them from a pile
Nim-sum (XOR of pile sizes)
0
Sprague-Grundy: the XOR strategy
Bouton's theorem (1901): a position with piles (a, b, c) is a losing position for whoever moves next if and only if a ⊕ b ⊕ c = 0 (where ⊕ is XOR / binary addition without carry).
Why: if the nim-sum is 0, any move you make changes one pile to a new value, which changes the nim-sum to something nonzero. Then your opponent can always make a move bringing it back to 0. By induction, the player facing nim-sum 0 must eventually take the last stone — and lose.
Conversely, if the nim-sum is nonzero (let h be the leftmost set bit), find a pile whose size has bit h set. Reduce that pile to pile_size ⊕ nim-sum. This makes the new nim-sum 0, handing your opponent a losing position.
Sprague-Grundy (1935): every impartial game with finite play is equivalent to a single Nim pile of some size — its Grundy number. A disjunctive sum of multiple games equals the XOR of their Grundy numbers. This collapses the analysis of an enormous family of combinatorial games (Wythoff's game, Turning Turtles, Hackenbush, Nim variants) into XOR arithmetic.
Try the game: when nim-sum > 0, you have a winning move. Click "show optimal move" to find it. The computer will then move to a losing position for you — if you ever face nim-sum 0, the game is lost no matter what you do.