ASI AppsWrite

Games and exercises

PsyGames

Tower of Hanoi: rules and how to play

Tower of Hanoi game rules: move the whole stack of discs from the left peg to the right one, one disc at a time, never a larger disc on a smaller.

What is the Tower of Hanoi?

The Tower of Hanoi, sometimes written Towers of Hanoi, is one of the best known logic puzzles. It has three pegs and a stack of discs with holes in the middle, ordered by size, with the largest at the bottom and the smallest on top. The task is to move the whole tower to another peg while obeying one restriction. The Tower of Hanoi game is simple to describe and surprisingly deep: even a short tower hides a long, exact sequence of moves. In PsyGames the app card states the task as: move all discs to the right peg. The game sits in the Sorting hub.

The goal and the rules

The tower starts on the left peg, and it has to end on the right peg. Three rules cover everything.

  • One disc per move. You move a single disc at a time.
  • Only the top disc. A disc can be lifted only if nothing lies above it on its peg.
  • Never larger on smaller. A disc may be placed on an empty peg or on a larger disc. It may never be placed on a smaller one.

In the classic puzzle the middle peg is the helper: you use it as a place to park discs on the way. Nothing else is limited, so you can move as many times as you like, but the shortest solution is fixed by the size of the tower. The app description does not say how many discs a level uses or how you pick up and drop a disc, so those are details to learn on screen.

How to play Tower of Hanoi in PsyGames

The task in the Tower of Hanoi game is to carry the tower from the left peg to the right one while a larger disc never sits on a smaller one. Start every level by looking at the number of discs and the pegs, because the number of discs decides how long the solution is. The description lists no timer, no move limit and no hint button. Before you touch a disc, name the move you want to finish, such as “the largest disc to the right peg”, and then work back from there. This is how the classic solution is found.

A worked example

Take a tower of three discs, with 1 as the smallest and 3 as the largest, and call the pegs left, middle and right. The shortest solution takes 7 moves.

  1. Disc 1 goes from the left peg to the right peg.
  2. Disc 2 goes from the left peg to the middle peg.
  3. Disc 1 goes from the right peg to the middle peg, onto disc 2.
  4. Disc 3 goes from the left peg to the right peg. Now the largest disc is where it belongs.
  5. Disc 1 goes from the middle peg to the left peg.
  6. Disc 2 goes from the middle peg to the right peg, onto disc 3.
  7. Disc 1 goes from the left peg to the right peg, onto disc 2. The tower is done.

Look at the shape of the solution. The first three moves carried the two small discs out of the way, onto the middle peg. Move 4 carried the largest disc. The last three moves put the two small discs back on top of it. This is the recursive idea in miniature.

The recursive method

To move a tower of n discs from one peg to another, first move the top n minus 1 discs to the spare peg, then move the largest disc to the target, and finally move the n minus 1 discs from the spare peg onto the target. The same method then solves each smaller tower inside it. Any Hanoi tower puzzle has a fixed shortest solution: it has 2 to the power n, minus 1 moves, so 1 disc needs 1 move, 2 discs need 3, 3 discs need 7 and 4 discs need 15.

A handy rule for doing it without much thought: every second move is made with the smallest disc, and the smallest disc keeps going round the pegs in one direction. With an odd number of discs, the smallest disc’s first move goes to the target peg. With an even number, it goes to the spare peg. On the other moves there is only one legal move that does not involve the smallest disc, so you just make it.

Tips and common mistakes

  1. Do not grab the nearest legal move. Several moves are always legal, but only one fits the plan.
  2. Decide where disc 1 goes first. The wrong first move for the smallest disc makes the tower end on the wrong peg, which you may notice only many moves later.
  3. Think of the largest disc as the milestone. Everything before it is clearing the way, and everything after it is rebuilding the tower.
  4. Do not undo the move you just made. Moving the same disc back and forth never makes progress.
  5. Add one disc at a time. A solved tower of three is the first half of a tower of four, which makes the longer puzzle easier to see.
  6. Count your moves. If you have used more moves than the formula allows, there is a shorter path, and looking for it is part of the fun.

How Tower of Hanoi differs from similar games

The sorting games in the same hub, such as Test Tubes and Ball Sort, move items between containers according to colour. Hanoi has no colours: the only thing that decides where a disc may go is its size. Another puzzle in the same hub is Tower of London; see its own page for its rules. The whole list is in the all games catalogue.

Tower of Hanoi in PsyGames

You find the game in the Sorting hub, next to Test Tubes, Ball Sort, Nut Sort, Cake Sort, Pizza, Goods Sort and Tower of London. The app card asks for a simple thing, move all discs to the right peg, and leaves everything else, such as the number of discs, to the level you open.

Frequently asked questions

What are the rules of the Tower of Hanoi?

There are three pegs and a stack of discs of different sizes. You move the stack from the first peg to the last, one disc at a time, and you may never place a larger disc on top of a smaller one.

What is the minimum number of moves?

For a tower of n discs the fewest possible moves is 2 to the power n, minus 1. Three discs need 7 moves, four need 15 and five need 31.

Which disc may I move?

Only a disc that lies on top of a peg. A disc with another disc above it cannot be moved until the upper one is gone.

Which peg does the tower have to end up on in PsyGames?

On the right peg. The app asks you to carry the tower of discs from the left peg to the right one.

More games in this section

All games

PsyGames: Brain Training

Learn more: PsyGames