In a temple said to mark the centre of the world, sixty-four golden disks rest on three diamond needles. Since the day of creation, priests have moved the disks one at a time — never a larger disk upon a smaller — and the day they finish rebuilding the tower on the third needle, the temple crumbles to dust and the world ends.
Rest easy. Rebuilding a 64-disk tower takes 264−1 = 18,446,744,073,709,551,615 moves. At one move a second that is about 585 billion years — and the universe is only ~13.8 billion years old. The puzzle was invented by the French mathematician Édouard Lucas in 1883 and sold as the toy La Tour d’Hanoï; the doomsday legend was his marketing.
Towers of Hanoi is the textbook example of recursion: to move a stack of N disks, first move the top N−1 out of the way, move the big one, then put them back on top.
But the CP1 has only an accumulator and no call stack to remember every pending “put them back.” The solver builds one by hand in memory — four parallel software stacks (the three pegs plus return addresses) in cells 200–255, grown by a save_and_push prologue and unwound by pop_and_restore. A 1983 decimal trainer doing honest recursion — up to thirteen disks.
As it solves, the CP1 streams each move — which disk, from which peg to which — over a four-bit GPIO protocol to an Arduino Mega 2560, which renders the tower on the 64×32 RGB LED matrix: disks rainbow-coloured by size, sliding between three pegs on a blue base. It is the very move protocol first built to drive a physical pan/tilt Hanoi robot — now painting pixels instead.
And getting the program onto the CP1 is painless: a modern development toolchain turns readable assembly into a cassette WAV you play straight into the tape input — no hand-keying 256 cells on the keypad.
Full solve on the LED matrix, plus the CP1 & Microtronic source, the robot, and the code walk-through.
github.com/lambdamikel/towers-of-hanoi
youtu.be/CkCNBzWRjq4