Tower of Hanoi

Tower of Hanoi, also called Towers of Hanoi or Towers of BrahmaTower of Hanoi.puzzle involving three vertical pegs and a set of different sized disks with holes through their centres. The Tower of Hanoi is widely believed to have been invented in 1883 by the French mathematician Édouard Lucas, though his role in its invention has been disputed. Ever popular, made of wood or plastic, the Tower of Hanoi can be found in toy shops around the world.

The typical toy set consists of three pegs fastened to a stand and of eight disks, each having a hole in the centre. The disks, all of different radii, are initially placed on one of the pegs, with the largest disk on the bottom and the smallest on top. The task is to transfer the stack to one of the other pegs subject to two rules: only individual disks may be moved, and no disk may be placed on a smaller disk.

It can be shown that for a tower of n disks, there will be required 2n − 1 transfers of individual disks to shift the tower completely to another peg. Thus for 8 disks, the puzzle requires 28 − 1, or 255 transfers. If the original “needle” (peg) was a tower with 64 disks, the number of transfers would be 264 − 1, or 18,446,744,073,709,551,615; this is exactly the same number required to fill an 8 × 8 checkerboard with grains of wheat, 1 on the first square, 2 on the second, 4 on the next, then 8, 16, 32, and so forth.

According to a legend of obscure origin, there exists a Vietnamese (or, sometimes, Indian) temple or monastery where priests have been shuffling golden disks between three pegs for many centuries. When the priests finally succeed in transferring all of the disks, the world will end. In some versions of the legend the priests are only allowed one move per day, though even allowing one move per second would require more than 500 billion years to complete the task.

The implausibility of finishing such a task was used for comedic effect in “Now Inhale,” a 1959 classic science fiction story by American Eric Frank Russell, in which the protagonist is allowed to play one “game” from Earth before being executed on an alien planet.