Towers of Hanoi

A classic Stock Puzzle, invented in 1883 by Edouard Lucas. The player is given three poles in a row, and at least three discs of different sizes stacked on the pole on one side. The object is to get the discs from the pole on one side to the pole on the other by moving the discs, one at a time, from one pole to another, in as few moves as possible. The player can only move the top disc on any stack, and cannot place a bigger disc on a smaller disc.

There is an (apocryphal) legend about a lost temple where the priests of Brahma, in accordance with an ancient prophecy, basically spend their time playing Towers of Hanoi... with 64 disks of solid gold. Furthermore, the prophecy states that when the puzzle is finally solved, the world will end. The legend was invented by Lucas himself when he distributed the original puzzle under the Significant Anagram N. Claus (De Siam), for E. Lucas (D'Amiens). Note that if this legend were true, even if the priests were able to move one disc per second, it would take 584,942,417,356 years, 26 days, 7 hours and 15 seconds for them to solve it. So we have nothing to worry about in any case.

Often used as an introduction to the concept of recursion in programming classes. Solving it requires moving n-1 discs onto the vacant pole, then the nth disc onto the target, then the previous pile of n-1 discs on top of that one, thus requiring a total of (2^n)-1 moves. It's also a common, seemingly random obstacle in video games.

The recursive solution is, roughly:
  1. If there is only one disk move it directly from the source peg to the target peg. Otherwise:
  2. Ignore the bottom disk of the tower on the source peg, and solve the Towers of Hanoi problem from the source peg to the spare peg, using the target peg as a spare. The spare peg now has a tower of n-1 disks on it, and the source peg has one disk (the biggest) on it.
  3. Move the single disk from the source peg to the target peg.
  4. Solve the Towers of Hanoi problem from the spare peg to the target peg using the source peg as a spare.

This counts as a solution because the "solve the Towers of Hanoi" steps in (2) and (4) are for towers one disk smaller than the previous. Solving the problem for n disks can be done if you know how to do it for n-1 disks, which can be done if you know how to do it for n-2 disks, &c... until you get down to doing it for one disk, which is trivial.

If the disks are numbered, human solvers can use as a memory aid the fact that it is never correct to place an odd-numbered disk directly on top of another odd-numbered disk, and likewise for even-numbered disks.

Amusingly, at least one Brahmin monastery has adopted the puzzle as a genuine devotional exercise, using approximately 30 brass discsnote . No word if the puzzle's completion will mark the end of the current universe.


    open/close all folders 

     Card Games  

  • Perplex City borrows the Hindu legend for the card Tower of Cubes, though their temple only has 36 cubes to work with, and completing the puzzle will end all sorrow and grief in the universe.
    • If you move one disc per second, this would take 2,179 years, 29 days, 7 hours, 32 minutes and 15 seconds. Not as long as the other example.

     Fan Fiction  

  • In the System Shock fanfic Free Radical, a robot was set to do a twenty-piece version to prevent SHODAN from being able to connect to it when it went for new orders.


  • "Bright Eyes", the ape in Rise of the Planet of the Apes, is seen flying through this puzzle, though it was a four disc variant and she was tested on it repeatedly.


  • In Eric Frank Russell's story "Now Inhale", the protagonist is sentenced to death on an alien world. Traditionally, the condemned plays a game with the warder, and when it ends (win or lose) he is executed. To stretch the game out until rescuers arrive, our hero chooses the Towers of Hanoi, referencing the above legend. When the aliens discover they've been duped, they change the rules so that offworld games are not allowed.

     Live-Action TV  

  • In the Doctor Who serial "The Celestial Toymaker" (now a lost story except for the final episode, but available in full on audio), the Doctor is challenged to solve a 10-disc version of the Towers of Hanoi, known as The Trilogic Game. The Doctor realises that the Toymaker's world will vanish once he makes the last move, so he finishes it inside the TARDIS.
  • On Survivor Thailand (U.S. season 5), a large five-disk version of this puzzle was an immunity challenge. One competitor, Shii-Ann, a computer programmer, seemed to have no clue at all of how to solve it, leading to some Epileptic Trees from fans about both her meta-game strategy and the actual backstage operations of the show


  • The MMORPG EverQuest has a quest where you have to play Towers of Hanoi, although they don't call it that.
  • In Star Wars: The Old Republic, the Fabricator boss in the Karraga's Palace Operation requires some members of the party to solve this type of puzzle to arm the cannon that lowers the boss' defenses.

     Video Games  

  • One of the activities in Math Blaster Pre-Algebra is a variation on the Towers of Hanoi where barrels in the basement must be stacked to solve a math problem. Rather than varying sizes of barrels, it uses varying numbers on the barrels which must add up to the number on the platform. There are three places to put the barrels and four barrels. There are two platforms which may or may not have different numbers.
  • An old DOS and Apple II game called Monkey Business revolved around this — a stack of monkeys is trying to reach the apples on the tree next to them, conveniently the same distance from the ground as their combined height.
  • BioWare seems to like this puzzle:
  • A side quest in Black & White has you doing this to move a temple further up the shore of a lake so it doesn't get flooded out during high tide. The inclusion of "classic" puzzles caused some reviewers to wonder whether Hanoi Towers and garbage collecting is really what gods do.
  • The stairway puzzle in Ultima VIII is a version with stair steps.
  • This is the last puzzle in The Legend of Kyrandia: Hand of Fate.
  • To finish Zork Zero, the player has to go through this twice (at least). Even nastier, you're not allowed to save while in the room, and if you put a big disc onto a smaller one, it crushes the smaller one, making the game Unwinnable. Hope you saved often!
  • Subverted in the Interactive Fiction game The Magic Toyshop, where you're challenged to solve the puzzle in only six moves. The solution is to glue two of the disks together (using two moves), leaving you with a two-disk tower and four moves.
  • Professor Layton and the Diabolical Box, which uses pancakes in place of discs and plates instead of pegs.
  • A side mission to explore an abandoned mansion in Space Rangers 2 has this as one of the puzzles.
  • The third screen in The Island of Dr. Brain has this puzzle with 4, 5, or 7 discs, depending on the difficulty. Expect to be there a while on Expert difficulty making 127 moves.
  • The Tire Tower puzzle in The Secret Island of Dr. Quandary. 3 tires as B. Ginner, 4 as O.D. Nary, 5 as D. Feecult, and each with a limit on the moves you can use before your time is up and Quandary kicks you out of the junkyard.
  • Appears in its four-tier form in Mystery Of Mortlake Mansion.
  • All the time in the Nancy Drew series. There's one in The Haunting of Castle Malloy that springs to mind first.
  • One of the puzzles among the final trio of minigames near the end of Reah: Face the Unknown. This one plays it from the reverse angle (smallest in the back, largest in front). But it's annoying in the fact that, like the other two puzzles, you have to do three rounds of it, each one containing more pieces than the last.
  • Umang has to play a game of this in The Sacred Rings, using Russian doll-style statues, to place in the proper slot just so Reina can summon lightning for him.
  • The robot puzzle in the secret laboratory in IHOG Questerium: Sinister Trinity is the five-tier form. The discs (or lenses in this case) have to end up on the middle pole, so that green light can shine through them to germinate a plant seed.
  • 3-D Ultra Lionel Traintown has a Tower of Hanoi puzzle as one of the game's missions, which is played with train cars.
  • In the video game adaptation of All Dogs Go to Heaven (which is a Minigame Game), there is a Towers of Hanoi-styled minigame.
  • Sunless Sea: The Emperor's Tomb in the Empire of Hands has this puzzle as one of the various obstacles, in this case acting as the door's lock. It's lampshaded as an easy and overused Stock Puzzle, matching with the general mockery of jungle temple tropes in this mission, but this one also has 15 disks, making it horribly tedious and it's also badly-made, and won't actually open the door when it's solved. Fortunately, you brought dynamite.

     Real Life  

  • A common test (amongst others) for diagnosing schizophrenia. Schizoid-type disorders are notable for an inability to plan means-to-a-goal actions and so are impaired at the puzzle.