A recursive solution solves a problem by solving a smaller copy of itself. Draw that idea instead of running it and you get a fractal: a shape made of smaller copies of itself, all the way down.
Move the whole tower from the left peg to the right one. Move one disk at a time and never put a bigger disk on a smaller one. To move n disks: move the top n − 1 out of the way, move the biggest disk, then move the n − 1 back on top. That's the entire solution.
How to read this: on the pegs, disk color only tracks size. In the tree below them, each dot is one move. Higher dots move bigger disks, and every dot sits between the two smaller jobs it waits on.
Try this: switch to Solve it yourself with 3 disks (the gold peg is the one you picked), then compare your moves with the gold Fewest possible count.
Each line is a job waiting on the one below it; the gold line is moving a disk right now. Depth counts the waiting jobs.
def hanoi(n, src, dst, spare): if n == 0: return hanoi(n-1, src, spare, dst) # clear the way move(n, src, dst) # biggest disk hanoi(n-1, spare, dst, src) # restack on top
Each extra disk doubles the work. The legend's 64 golden disks, at one move a second, would take about 585 billion years.
Each shape is one short recursive rule applied over and over. Raise the depth and watch it draw in the order the recursion visits each piece.
Try this: Fractal tree at depth 10, then drag Angle.
Pick a point c on the complex plane. Start at z = 0 and repeat z → z² + c. If z stays close to the origin forever, c is in the set (black). Colors show how fast the other points fly away. Click to zoom in ×3, and hover to watch a point's path.
How to read this: hover a point: the gold ring is the point you picked, and the dots show where repeating the rule takes it. The colored bands repeat; each band is one more step before the point escapes, so they don't run from fast to slow.
Try this: click Seahorse valley, then keep clicking a curl. Right-click or Shift-click zooms back out.
Once |z| passes 2, squaring it grows faster than adding c can pull it back, so it escapes to infinity. The renderer stops at that point and colors the pixel by how many steps it took.
Zoom into any bulb's edge and you find smaller copies of the whole set, each with its own bulbs and its own copies. The boundary is so crinkled that its fractal dimension is exactly 2, as Shishikura proved in 1998. The area is still unknown, but it's estimated at about 1.5066.