64 Rings, and 584 Billion Years at One Move a Second
Thirty-two rings really do take 136 years at a move a second, which is what makes doubling it to 272 so tempting. The exact ratio between the two cases factors as two to the thirty-two plus one, so the guess is short by more than four billion times. The article carries the lower bound the recursion alone does not give, and the 2-adic rule for which ring moves when.
Sixty-four rings of distinct sizes sit stacked on one of three pegs, widest at the bottom. Move the whole stack to another peg. You may move one ring at a time, and no ring may ever rest on a smaller one. How long does it take at one move a second?
There is a good anchor available and it is a trap. Thirty-two rings take moves, which is a little over four billion seconds, which is years. That figure is correct. Doubling it because sixty-four is twice thirty-two is the mistake, and the answer it produces is wrong by a factor of four billion.
The recursion, and why it is the whole problem
Let be the minimum number of moves for rings. To move rings you have to move the largest one at some point, and to do that the other must all be sitting on the peg you are not using. So the sequence necessarily splits into three parts.
and the closed form follows by induction, since :
The part usually skipped is that (1) is an equality rather than an upper bound. Read left to right it says a strategy exists using that many moves. Read as a bound it says no strategy uses fewer, and that direction needs the argument in Fig. 1 stated as a constraint: before the largest ring can move at all, the smaller rings must already be stacked on a single peg, which is itself an instance of the same problem and therefore costs at least . After the largest ring is in place, the smaller ones must be brought onto it, another at least. So
and with the induction gives . Combined with the strategy, that is an exact answer rather than a good one.
The positions of the puzzle form a graph on vertices, one per assignment of rings to pegs, with an edge for each legal move. The answer is the graph distance between two corner vertices, and a breadth-first search computes it with no recursion at all. Run for to it returns every time.
What doubling the rings actually costs
For sixty-four rings,
which is about moves. The reason the linear guess fails so badly is that the ratio between the two cases is not two, and it factors exactly:
using the difference of squares on . So the guess of years is short by more than four billion times. This is the shape of every mistake people make with exponentials: the intuition treats as a multiplier on the cost when it is an exponent, and doubling an exponent squares the answer.
Five hundred and eighty-four billion years
Turning (4) into a duration needs one convention stated rather than assumed, because at this precision the choice of year is visible. Using the Julian year of days, that is seconds, and
A calendar year of exactly days would give billion instead, so the third digit is a convention and not a measurement. The same divisor turns seconds into years, which is where the anchor in the trap comes from.
Taking the age of the universe as billion years puts the answer at about times that, which is the comparison I would use if I only had one sentence. The factor depends on a measured quantity, so "about forty-two" is the honest form of it.
What the number rules out
One move a second is an arbitrary rate, so it is worth asking what rate would be needed to make the task possible at all. Dividing (4) by the age of the universe in seconds gives about moves a second, sustained without a break since the beginning of time. Speed does not rescue this. Going a thousand times faster still leaves a duration of six hundred million years, and going a billion times faster leaves six centuries.
The same arithmetic settles a related question that people reach for, which is whether you could at least write the solution down. The sequence has entries, and even at one byte each that is eighteen exabytes, comfortably more than the total storage manufactured in a year. What saves the situation is (7) below: the sequence is compressible to a rule, so you never have to store it, only regenerate it. That is the difference between an answer of exponential size and a problem of exponential difficulty.
Which ring moves on move k
The optimal sequence has a closed form of its own, which is worth knowing because it turns the recursion into something you can execute without a stack. Number the rings from the smallest, and at move the ring that moves is
where counts the trailing zeros in the binary form of . For three rings that reads , which is the optimal solution written out. The smallest ring moves on every odd step, so it accounts for just over half of all moves, the next ring for a quarter, and the largest ring moves exactly once, on step . The pattern is the same one you get from the tick marks on a ruler, which is where its usual name comes from.
Add a peg and the problem changes character
The three-peg answer is elementary and exact. Allow a fourth peg and you can do far better, because the rings no longer have to end up on one peg before the largest moves, and the natural recursion splits the stack into two groups whose sizes you get to choose. The resulting count is much smaller and much harder to pin down: the algorithm everyone uses was proposed in 1941 and only proved optimal for four pegs in 2014. For five pegs and beyond it remains open.
I find that the most interesting fact in the neighbourhood. The version with a legend attached has a one-line answer, and the version with one extra peg was an open problem for seventy-three years.
Sources and further reading
- The puzzle, the recursion in (1) and the sequence in (7) — Tower of Hanoi
- Solving (1) in closed form — Recurrence relation
- The function in (7) — OEIS A001511 and the 2-adic valuation
- The four-peg counts — OEIS A007664
- The age used for the comparison — Age of the universe
Every figure above was checked before publication in three ways: symbolically, by a breadth-first search over the complete state graph for to which confirms the count is a genuine minimum rather than an achievable one, and by a move-by-move play-out of the strategy for up to that raises on any illegal placement. Durations were computed in exact integer and rational arithmetic.
Comments · 0
Be the first to comment.