The Tower of Hanoi puzzle is a game that was invented by the French mathematician Édouard Lucas in 1883. It is a mathematical brain teaser where you try to move an entire pile of disks from one peg to another, and then back again, one disk at a time without ever putting any larger disk on top of any smaller disk. If all the pegs were filled with disks, then you will have to remove some before you can begin moving them around.
The Tower 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.
Goal is to move the entire stack from one rod to another according to the following rules:
- Only one disk may be moved at a time
- A larger disk may not be placed on top of a smaller disk
- A larger disk must always be placed on either the first or last rod (except when starting)
Start by moving all but one disc from the leftmost rod to any other rod in order
Move remaining disc from leftmost rod to rightmost rod, then move discs from second leftmost to second rightmost etc until you reach original rightmost (or just keep going if there are no more discs)
Repeat as necessary with next tower and so forth until game is won!
How to Play Tower of Hanoi?
You can play Tower of Hanoi with any number of disks, but the most common values for n are three or seven.
- To start, pick a disk from the pile and move it to another peg that is not yet filled. You may only make one move at a time; you cannot jump over empty pegs in between your destination peg and source peg as there will be no space left on either side if you do so.
- Place this new disk onto its final resting place by moving all other disks off the first hole then placing them back on top of each other until they reach their original position beside (or above) the newly placed disk.
- After completing these moves, repeat steps two through four until all discs are in their original positions.