Towers of Hanoi

The Towers of Hanoi is a mathematical puzzle that consists of three rods and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

The objective is to move all the disks from one rod to another, obeying these rules:

  • Only one disk may be moved at a time.
  • No disk may be placed on top of a smaller disk.
  • A larger disk may not be placed on top of a smaller disk.

The puzzle can be solved by moving all the disks from one rod to another in as few moves as possible.

The more blocks there are the more difficult the puzzle becomes.

This is a great puzzle to get you thinking logically about the sequence of events / moves that you are making.


The Towers of Hanoi puzzle using just 3 disks. Suitable for beginners to the Towers of Hanoi puzzle.

The Towers of Hanoi puzzle using 4 disks. Suitable for those who already know how the Towers of Hanoi puzzle works.

The Towers of Hanoi puzzle using 5 disks. Suitable for those who already know how the Towers of Hanoi puzzle works.

NB – the base for this code came from https://bitbucket.org/ninchester/towers-of-hanoi/src/0db42396423d9bb15f542fbfc81302593e0a2db2/TowersOfHanoi/?at=master