Skip to content
shubham vernekar edited this page Dec 25, 2018 · 1 revision

Introduction

The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of three stands, and a number of plates of different sizes which can be put over each other on any stand.

The puzzle starts with the plates stacked in order of size on one stand we call source, smallest at the top, making a pyramid shape.

The object of the game is to move the entire stack to another stand (destination), obeying the following rules:

  • Only one disc may be moved at a time.
  • No disc may be placed on top of a smaller disc.

Solution

Recursive Algorithm

Label the stands Src, Intr, Dest.
Let n be the total number of discs.
Number the discs from 1 (smallest, topmost) to n (largest, bottommost). 

To move n discs from stand Src to stand Dest:

Move n-1 plates from Src to Intr. This leaves plate #n alone on plate Src.
Move plate #n from Src to Dest.
Move n-1 plates from Intr to Dest so they sit on plate #n. 

Screenshots

For more details refer report of project. The report of project is along with project

Clone this wiki locally