The Towers of Hanoi is one of the most famous puzzles in computer science. Three pegs stand in a row. On the first sits a stack of disks, largest at the bottom, shrinking to the top. Your goal: move the whole stack to the third peg. The rules are tiny — move one disk at a time, and never put a larger disk on a smaller one.
What makes it beloved is that a single idea solves it perfectly. To move n disks from A to C: first move the top n-1 disks out of the way to B, then move the biggest disk to C, then move those n-1 disks from B onto C. That's the whole algorithm — a three-line recursion that never makes a wrong move.
So the thinking is easy. The catch is hiding somewhere else entirely — not in how hard it is to figure out the moves, but in how many moves there are.
Comments
Loading comments...