In 1883, a French mathematician sold a toy with a prophecy attached: when monks finish moving 64 golden discs, the world will end.
The toy was the Tower of Hanoi. Édouard Lucas published it under the name "N. Claus de Siam," an anagram of "Lucas d'Amiens," and he wrote the legend himself.
The rules fit in one line. Move the whole stack to another peg, one disc at a time, never putting a bigger disc on a smaller one.
The solution fits in three. To move n discs: move the top n − 1 to the spare peg, move the biggest disc, then move the n − 1 back on top.
That gives T(n) = 2 · T(n − 1) + 1, which works out to 2ⁿ − 1 moves.
3 discs: 7 moves.
10 discs: 1,023.
20 discs: 1,048,575. At one move per second, that's 12 days.
30 discs: 1,073,741,823. About 34 years.
Every extra disc doubles the job.
Nobody can do it faster, either. The biggest disc has to move at least once, and before it can, every other disc must be stacked on the spare peg. That forces the recursion, so 2ⁿ − 1 is the minimum.
Now the monks' 64 discs.
2⁶⁴ − 1 = 18,446,744,073,709,551,615 moves.
At one move per second, that's about 585 billion years, roughly 42 times the current age of the universe. The job outlasts the universe as early as 59 discs.
The algorithm is already perfect, and the problem doubles with every disc anyway.
Lucas's monks are safe. So is the world.
Four lines of code. If you could tell whether they ever stop, you'd solve a math problem that has been open since 1742.
n = 4
while is_sum_of_two_primes(n):
n = n + 2
halt
The program walks through every even number and checks whether it's the sum of two primes. 100 = 3 + 97. 1,000,000 = 17 + 999,983. As long as the answer is yes, it keeps going.
It stops only if it finds an even number that fails. That would disprove Goldbach's conjecture, which Christian Goldbach sent to Euler in a letter in 1742. Computers have checked every even number up to 4 × 10¹⁸, and every one passes.
So a program that reliably answers "does this code halt?" would settle Goldbach without a proof. You'd feed it these four lines and read the verdict.
In 1936, Alan Turing proved that program can't exist.
The argument is short. Suppose a decider H exists: give it any program and input, and it correctly says whether the program halts. Now build a program D that hands a program its own code, asks H about it and does the opposite. If H says "halts," D loops forever. If H says "loops," D stops.
Then run D on itself.
If D(D) halts, H must have said it loops. If D(D) loops, H must have said it halts. Either way H is wrong about D, so H can't exist.
Faster hardware doesn't help. A decider that works for every program is logically impossible.
Individual programs are often easy. A counter halts after 23 steps. A loop that hits the same state twice never stops. Start the Collatz sequence at 27 and it climbs to 9,232 before reaching 1 after 111 steps, though nobody has proved every starting number gets there.
A simulation going around runs all of these. The simple programs get a verdict. Goldbach comes back unknown. The general decider comes back impossible.
That's what makes Turing's result so frustrating. The impossible machine would answer Goldbach, Collatz and any other conjecture you can turn into a search.
In 1750, a player in a Paris café gave away his queen on move 5. Two moves later the game was over, and he had won.
1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1
Black grabs the queen. Count the material and White is down 8 points: 30 against 38.
6. Bxf7+ Ke7 7. Nd5#
Checkmate. The trap is still named after him: Légal's mate, after Kermur de Légal, the man who taught Philidor.
A short chess simulation going around replays it to show why an engine never falls for it, and what that costs.
A material count looks one move deep, and it says White is losing. Search three plies ahead, White's move, Black's reply, White's move, and the score flips to forced mate.
Plain minimax checks every line to that depth: 49,642 positions in 3.2 seconds. Alpha-beta finds the same answer after 1,382 positions in 89 milliseconds. That's 36 times less work for an identical result. It prunes a branch the moment it proves the branch can't change the outcome. Donald Knuth and Ronald Moore worked out why in 1975.
Pruning only goes so far, though. Chess offers about 35 legal moves per position. Claude Shannon estimated the full game tree at around 10^120 in 1950. John Tromp counted the legal positions at roughly 10^44.
So a mate in two is solved in a couple of seconds, while chess itself remains unsolved. Generalize the board to n × n and the problem is EXPTIME-complete, as Aviezri Fraenkel and David Lichtenstein proved in 1981. That class is provably harder than anything solvable in polynomial time.
Légal needed to see three moves ahead. Solving chess would mean seeing all of them.