Towers of Hanoi

Towers of Hanoi

(games)A classic computer science problem, invented byEdouard Lucas in 1883, often used as an example ofrecursion.

"In the great temple at Benares, says he, beneath the domewhich marks the centre of the world, rests a brass plate inwhich are fixed three diamond needles, each a cubit high andas thick as the body of a bee. On one of these needles, atthe creation, God placed sixty-four discs of pure gold, thelargest disc resting on the brass plate, and the othersgetting smaller and smaller up to the top one. This is theTower of Bramah. Day and night unceasingly the prieststransfer the discs from one diamond needle to anotheraccording to the fixed and immutable laws of Bramah, whichrequire that the priest on duty must not move more than onedisc at a time and that he must place this disc on a needle sothat there is no smaller disc below it. When the sixty-fourdiscs shall have been thus transferred from the needle onwhich at the creation God placed them to one of the otherneedles, tower, temple, and Brahmins alike will crumble intodust, and with a thunderclap the world will vanish."

The recursive solution is: Solve for n-1 discs recursively,then move the remaining largest disc to the free needle.

Note that there is also a non-recursive solution: Onodd-numbered moves, move the smallest sized disk clockwise.On even-numbered moves, make the single other move which ispossible.

["Mathematical Recreations and Essays", W W R Ball, p. 304]

The rec.puzzles Archive.