Lay out a few rows of coins. Two players take turns; on your turn you remove any number of coins — but all from a single row. Take the last coin and you win. It looks like a game of intuition, yet it has a complete, provably perfect solution hiding in one strange operation: the binary XOR. Play the unbeatable AI below, then peek behind the curtain at the math that makes it impossible to beat.
Click a coin to take it and every coin to its right in that row (so one click removes 1, 2, 3… from a single row). Then the AI replies. In normal play whoever takes the last coin wins; flip on misère and whoever takes the last coin loses. The AI plays perfectly under whichever rule is active — from a winning start, it cannot be beaten.
Write each heap's size in binary and add the columns without carrying — that's XOR, also called the nim-sum. The whole theory is one sentence: a position with nim-sum 0 is losing for the player about to move (a P-position), and any other position is winning. The perfect move always leaves the nim-sum at 0, handing your opponent a hopeless position. Drag the sliders and watch it light up. The AI in scene 1 is doing exactly this.
Nim is the cornerstone of combinatorial game theory: two players, perfect information, no chance, and the last legal move decides it. Every such position is either a P-position (the Previous player — the one who just moved — wins, i.e. it's a loss for whoever is about to move) or an N-position (the Next player to move wins).
A game you could explain to a child, solved completely by a piece of binary arithmetic. That's the quiet beauty of Nim.