Tower of Hanoi

Author Topic: Tower of Hanoi  (Read 1560 times)

Offline Masuma Parvin

  • Sr. Member
  • ****
  • Posts: 323
    • View Profile
Tower of Hanoi
« on: November 13, 2012, 02:51:40 PM »
The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower,[1] and sometimes pluralised) is a mathematical game or puzzle. It 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 of the puzzle is to move the entire stack to another rod, obeying the following rules:

   1. Only one disk may be moved at a time.
   2.Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that   may already be present on that rod.
   3. No disk may be placed on top of a smaller disk.

Origins:
The puzzle was first publicized in the West by the French mathematician Édouard Lucas in 1883. There is a history about an Indian temple in Kashi Vihswanath which contains a large room with three time-worn posts in it surrounded by 64 golden disks. Brahmin priests, acting out the command of an ancient prophecy, have been moving these disks, in accordance with the immutable rules of the Brahma, since that time. The puzzle is therefore also known as the Tower of Brahma puzzle. According to the legend, when the last move of the puzzle will be completed, the world will end.[2] It is not clear whether Lucas invented this legend or was inspired by it.


Solution:

The following solution is a simple solution for the toy puzzle.
Alternate moves between the smallest piece and a non-smallest piece. When moving the smallest piece, always move it to the next position in the same direction (to the right if the starting number of pieces is even, to the left if the starting number of pieces is odd). If there is no tower position in the chosen direction, move the piece to the opposite end, but then continue to move in the correct direction. For example, if you started with three pieces, you would move the smallest piece to the opposite end, then continue in the left direction after that. When the turn is to move the non-smallest piece, there is only one legal move. Doing this will complete the puzzle using the fewest number of moves to do so.

Recursive solution

A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached. The following procedure demonstrates this approach.

    label the pegs A, B, C—these labels may move at different steps
    let n be the total number of discs
    number the discs from 1 (smallest, topmost) to n (largest, bottommost)

To move n discs from peg A to peg C:

  1.  move n−1 discs from A to B. This leaves disc n alone on peg A
  2.move disc n from A to C
 3.   move n−1 discs from B to C so they sit on disc n

The above is a recursive algorithm: to carry out steps 1 and 3, apply the same algorithm again for n−1. The entire procedure is a finite number of steps, since at some point the algorithm will be required for n = 1. This step, moving a single disc from peg A to peg B, is trivial. This approach can be given a rigorous mathematical formalism with the theory of dynamic programming, and is often used as an example of recursion when teaching programming.


Offline msu_math

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Re: Tower of Hanoi
« Reply #1 on: November 13, 2012, 05:15:38 PM »
For n number of discs the total number of movements required is 2n -1.

Example:

1. No. of discs = 1     =>    Minimum no. of movements = 21 -1 = 1
2. No. of discs = 2     =>    Minimum no. of movements = 22 -1 = 3
3. No. of discs = 3     =>    Minimum no. of movements = 23 -1 = 7

etc
« Last Edit: November 19, 2012, 11:37:36 AM by msu_math »
Mohammad Salah Uddin

Lecturer in Mathematics
Department of Natural Sciences
FSIT, DIU

Offline snlatif

  • Faculty
  • Sr. Member
  • *
  • Posts: 267
    • View Profile
Re: Tower of Hanoi
« Reply #2 on: November 14, 2012, 02:50:24 PM »
Interesting one..

Offline Khandoker Samaher Salem

  • Full Member
  • ***
  • Posts: 144
    • View Profile
Re: Tower of Hanoi
« Reply #3 on: November 15, 2012, 05:37:39 PM »
Interesting !!!
Khandoker Samaher Salem
Lecturer (ACCT)
Dept. of Textile Engineering, FE
samaher@daffodilvarsity.edu.bd

Offline shirin.ns

  • Sr. Member
  • ****
  • Posts: 343
  • Test
    • View Profile
Re: Tower of Hanoi
« Reply #4 on: March 31, 2014, 02:28:04 PM »
Very interesting!!!
Shirin Sultana
Lecturer (Mathematics)
Dept. of General Educational Development (GED)
Daffodil International university