Nim, Solved

Nim is the fruit fly of game theory: simple enough to play in a bar, deep enough that its 1901 solution founded combinatorial game theory. Play it and lose; then look at the heaps in binary, learn which positions are balanced, and come back to beat a perfect opponent with a perfect strategy of your own.

deal
tableyou 0 · 0 ai
Nim board: heaps of stonesheap 1 · 3heap 2 · 4heap 3 · 5
Your move: click a stone to take it plus everything above it, from one heap. Last stone wins.

Write each heap in binary and read the columns, not the rows. Each column — the 1s, the 2s, the 4s — is its own little balance scale, and all it cares about is whether it holds an even or odd number of 1s. Call a board balanced when every scale is even. 3 · 4 · 5 is tipped; 1 · 3 · 5 · 7, the deal every hustler offers, is perfectly balanced.

Here's the trap: any move touches exactly one heap, so it tips at least one scale — but from a tipped board there is always a single-heap move that re-levels all of them at once. The AI plays only that move. You break, it balances, and the last balanced board is the empty one — reached on the AI's move, faced on yours.

The cure is the poison. Start from a tipped board, play the balancing move yourself, and the perfect AI is instantly in your trap — stalling, praying, losing.