50% found this document useful (2 votes)
3K views20 pages

Tower of Hanoi

The document summarizes a student project to build a machine that solves the Tower of Hanoi puzzle. It includes an introduction describing the puzzle, its origins in mythology, and the objectives of the project. It also provides an overview of the major components of the machine, including the turntable, elevator, and claw, and describes how they are controlled by a microprocessor. Solutions to the puzzle are presented, including the minimum number of moves required and iterative approaches.

Uploaded by

N Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
3K views20 pages

Tower of Hanoi

The document summarizes a student project to build a machine that solves the Tower of Hanoi puzzle. It includes an introduction describing the puzzle, its origins in mythology, and the objectives of the project. It also provides an overview of the major components of the machine, including the turntable, elevator, and claw, and describes how they are controlled by a microprocessor. Solutions to the puzzle are presented, including the minimum number of moves required and iterative approaches.

Uploaded by

N Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

A Micro Project On 2020-21

Tower of hanoi
BY

Under the Guidance of,

Mr.D.D.Borase.

Department of Computer Engineering,


Sau. Shantidevi Chavan Polytechnic,Bhoras

2020-2021

1|P a g e
Sau.Shantidevi Chavan Institute Polytechnic,Bhoras Chalisgaon-424101

CERTIFICATE

This is to certify that Mr. Pawar Rahul Dilip

Mr. Patil Kunal Shravan

Mr.Patil Vikas Vasudev

has successfully completed the micro Project on “TOWER OF HANOI”


under my supervision in the partially fulfillment of diploma of engineering
(computer)of Sau.Shantidevi Chavan Institute Polytechnic,Bhoras.
Date:

Place:

Prof.D.D.Borase Prof.Y.K.Pardeshi Prof.D.A.Patil


Project Guide HOD PRINCIPAL

2|P a g e
INDEX

Sr.no TOPIC PAGE.N


O
1 ACKNOWLEDGEMENT 4
2 ABSTRACT 5
3 INTRODUCTION 6
4 ORIGINS 8
5 SOLUTIONS 9
6 GRAPHICAL REPRESENTATION 12

7 APPLICATIONS 14
8 CODING 15
9 IN POPULAR CULTURE 17
10 CONCLUSION 19
11 REFERENCE 20

3|P a g e
Acknowledgement
We would take this opportunity to express my sincere thanks
and gratitude to my teacher Mr.D.D.Borase for his vital support
and guidance in completing this project.

We also express our gratitude to all the facility members,parents


and our fellow mates who have helped me in making this project
a success. We also thank our almighty God for his blessings
showed on me during this period.

Abstract
This report details the development and final implementation of the
Towers of Hanoi solver machine. It includes written descriptions of the
major subsystems, algorithms and functionality, as well as mechanical
and electrical diagrams and schematics and flowcharts of the software.
In addition, there is a lengthy discussion of the problems encountered
and their solutions, as well as where improvement could have been
made. A number of photographs of the final system are included in the
appendix at the end.

Introduction
The Tower of Hanoi (also called the Tower of Brahma or Lucas'
Tower and sometimes pluralized as Towers) is a mathematical

5|Page
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 simple rules:

1. Only one disk can be moved at a time.


2. Each move consists of taking the upper disk from one of the stacks
and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
With 3 disks, the puzzle can be solved in 7 moves. The minimal number
of moves required to solve a Tower of Hanoi puzzle is 2 n − 1, where n is
the number of disks.
The overall task for this project was to build a machine that physically
solves a given Towers of Hanoi puzzle set, according to the standard
rules for the game: move one disc at a time, only placing a disc on top of
a larger one. The goal is to transfer a stack of discs from one of three
pegs to another, using the third peg for intermediate moves, with any
peg arrangement. For this project, our systems had to meet additional
constraints for size; 2’x2’x2’ limitation, and for speed; a 3 time limit.
We were given a refundable budget of $200, with an extra $100
nonrefundable to spend. Each group was given a set of identical (within
tolerances) pegs and discs that we were not allowed to modify in any
way. Although the set included a wooden base to hold the three pegs, we
were not required to use it; we could mount the pegs any way we
wanted. On top of those basic requirements, we had to come up with a
“coolness factor.” Ours was a “manual mode” where the user can control
the machine through a computer serial connection. Our system consists
of three major components: the turntable, the elevator and the claw. The
three pegs are mounted to the turntable, equally spaced. The elevator is

6|Page
outside the perimeter of the turntable, and it lifts the claw up and down
so that it can manipulate the discs. Controlling everything is a PIC
16F877 microprocessor. Each of the subsystems and the software will be
elaborated upon in the following sections. Most of the system is
enclosed in a 2’x2’x1’ box made of 1/8” clear acrylic sheeting, which
we made from AutoCAD drawings using an automated laser-cutter.
There is a platform roughly twothirds of the way up where the turntable
sits. The elevator fixture sits on the floor, and extends through the
platform and above the top of the box to the 2’ maximum height. The
electronics are below the platform, out of the way of all moving parts

Origins

7|Page
The puzzle was invented by the French mathematician Édouard Lucas in
1883. Numerous myths regarding the ancient and mystical nature of the
puzzle popped up almost immediately. There is a story about
an Indian temple in Kashi Vishwanath 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
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 is completed, the world will end.
If the legend were true, and if the priests were able to move disks at a
rate of one per second, using the smallest number of moves it would take
them 264 − 1 seconds or roughly 585 billion years to finish, which is
about 42 times the current age of the universe.
There are many variations on this legend. For instance, in some tellings
the temple is a monastery, and the priests are monks. The temple or
monastery may be said to be in different parts of the world—
including Hanoi, Vietnam—and may be associated with any religion. In
some versions other elements are introduced, such as the fact that the
tower was created at the beginning of the world, or that the priests or
monks may make only one move per day.

Solutions

8|Page
The puzzle can be played with any number of disks, although many toy
versions have around 7 to 9 of them. The minimal number of moves
required to solve a Tower of Hanoi puzzle is 2n − 1, where n is the
number of disks. This is precisely the nth Mersenne number.

Iterative solution:-
A simple solution for the toy puzzle is to 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
in the fewest moves.

Simpler Statement Of Iterative Solution:-

For an even number of disks:

 make the legal move between pegs A and B (in either direction),
 make the legal move between pegs A and C (in either direction),
 make the legal move between pegs B and C (in either direction),
 repeat until complete.
For an odd number of disks:

 make the legal move between pegs A and C (in either direction),
 make the legal move between pegs A and B (in either direction),
 make the legal move between pegs B and C (in either direction),
 repeat until complete.

9|Page
In each case, a total of 2n − 1 moves are made.

Equivalent iterative solution:-


Another way to generate the unique optimal iterative solution:
Number the disks 1 through n (largest to smallest).

 If n is odd, the first move is from peg A to peg C.


 If n is even, the first move is from peg A to peg B.
Now, add these constraints:

 No odd disk may be placed directly on an odd disk.


 No even disk may be placed directly on an even disk.
 There will sometimes be two possible pegs: one will have
disks, and the other will be empty. Place the disk on the non-
empty peg.
 Never move a disk twice in succession.

10 | P a g e
Considering those constraints after the first move, there is only
one legal move at every subsequent turn.
The sequence of these unique moves is an optimal solution to the
problem equivalent to the iterative solution described above.

11 | P a g e
Graphical representation
The game can be represented by an undirected graph, the nodes
representing distributions of disks and the edges representing moves. For
one disk, the graph is a triangle:

The graph for two disks is three triangles connected to form the corners
of a larger triangle.
A second letter is added to represent the larger disk. Clearly it cannot
initially be moved.
The topmost small triangle now represents the one-move possibilities
with two disks:

The nodes at the vertices of the outermost triangle represent distributions


with all disks on the same peg.
For h + 1 disks, take the graph of h disks and replace each small triangle
with the graph for two disks.

12 | P a g e
For three disks the graph is:

 call the pegs a, b and c


 list disk positions from left to right in order of increasing size
The sides of the outermost triangle represent the shortest ways of
moving a tower from one peg to another one. The edge in the middle of
the sides of the largest triangle represents a move of the largest disk. The
edge in the middle of the sides of each next smaller triangle represents a
move of each next smaller disk. The sides of the smallest triangles
represent moves of the smallest disk.

13 | P a g e
Applications
The Tower of Hanoi is frequently used in psychological research
on problem solving. There also exists a variant of this task called Tower
of London for neuropsychological diagnosis and treatment of executive
functions.
Zhang and Norman used several isomorphic (equivalent) representations
of the game to study the impact of representational effect in task design.
They demonstrated an impact on user performance by changing the way
that the rules of the game are represented, using variations in the
physical design of the game components. This knowledge has impacted
on the development of the TURF framework for the representation
of human–computer interaction.
The Tower of Hanoi is also used as a backup rotation scheme when
performing computer data backups where multiple tapes/media are
involved.
As mentioned above, the Tower of Hanoi is popular for teaching
recursive algorithms to beginning programming students. A pictorial
version of this puzzle is programmed into the emacs editor, accessed by
typing M-x hanoi. There is also a sample algorithm written in Prolog.
The Tower of Hanoi is also used as a test by neuropsychologists trying
to evaluate frontal lobe deficits.
In 2010, researchers published the results of an experiment that found
that the ant species Linepithema humile were successfully able to solve
the 3-disk version of the Tower of Hanoi problem through non-linear
dynamics and pheromone signals.
In 2014, scientists synthesized multilayered palladium nanosheets with a
Tower of Hanoi like structure.

14 | P a g e
Coding
The tower of Hanoi is a mathematical 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. We have to obtain the same stack on
the third rod.
The objective of the puzzle is to move the entire stack to another rod,
obeying the following simple rules−
 Only one disk can be moved at a time.
 Each move consists of taking the upper disk from one of the stacks
and placing it on top of another stack i.e. a disk can only be moved
if it is the uppermost disk on a stack.
 No disk may be placed on top of a smaller disk.
Sample
Input  − 3
Output   − A to B 
              A to C 
              B to C 
       A to B 
       C to A 
       C to B 
A to B  Explanation − uses recursive function & solves the tower of Hanoi.

Example

#include<stdio.h>

void TOH(int n,char x,char y,char z) {

   if(n>0) {

      TOH(n-1,x,z,y);

15 | P a g e
      printf("\n%c to %c",x,y);

      TOH(n-1,z,y,x);

   }

int main() {

   int n=3;

   TOH(n,'A','B','C');

Output
A to B
A to C
B to C
A to B
C to A
C to B
A to B

In popular culture
16 | P a g e
In the science fiction story "Now Inhale", by Eric Frank Russell,[32] a
human is held prisoner on a planet where the local custom is to make the
prisoner play a game until it is won or lost before his execution. The
protagonist knows that a rescue ship might take a year or more to arrive,
so he chooses to play Towers of Hanoi with 64 disks. (This story makes
reference to the legend about the Buddhist monks playing the game until
the end of the world.)
In the 1966 Doctor Who story The Celestial Toymaker,
the eponymous villain forces the Doctor to play a ten-piece 1,023-move
Tower of Hanoi game entitled The Trilogic Game with the pieces
forming a pyramid shape when stacked.
In 2007, the concept of the Towers Of Hanoi problem was used
in Professor Layton and the Diabolical Box in puzzles 6, 83, and 84, but
the disks had been changed to pancakes. The puzzle was based around a
dilemma where the chef of a restaurant had to move a pile of pancakes
from one plate to the other with the basic principles of the original
puzzle (i.e. three plates that the pancakes could be moved onto, not
being able to put a larger pancake onto a smaller one, etc.)
In the film Rise of the Planet of the Apes (2011), this puzzle, called in
the film the "Lucas Tower", is used as a test to study the intelligence of
apes.
The puzzle is featured regularly in adventure and puzzle games. Since it
is easy to implement, and easily recognised, it is well-suited to use as a
puzzle in a larger graphical game (e.g. Star Wars: Knights of the Old
Republic and Mass Effect).[33] Some implementations use straight disks,
but others disguise the puzzle in some other form. There is an arcade
version by Sega.[34]
A 15-disk version of the puzzle appears in the game Sunless Sea as a
lock to a tomb. The player has the option to click through each move of
the puzzle in order to solve it, but the game notes that it will take 32767
moves to complete. If an especially dedicated player does click through
to the end of the puzzle, it is revealed that completing the puzzle does
not unlock the door.

17 | P a g e
In Yu-Gi-Oh! VRAINS, a hacking group called "Knight of Hanoi"
create a structure named "Tower of Hanoi" within the eponymous
VRAINS virtual reality network.
This was first used as a challenge in survivor Thailand in 2002 but rather
than rings, the pieces were made to resemble a temple. Sook Jai threw
the challenge to get rid of Jed even though Shii-Ann knew full well how
to complete the puzzle. The problem is featured as part of a reward
challenge in a 2011 episode of the American version of the Survivor TV
series. Both players (Ozzy Lusth and Benjamin "Coach" Wade)
struggled to understand how to solve the puzzle and are aided by their
fellow tribe members.

Conclusion

18 | P a g e
The main thing that we would do differently is to spend a lot more time
planning than we did, mainly by designing the whole thing in AutoCAD
or SolidWorks. If we had thought out the whole project earlier, we
would have seen a lot of the problems we ended up having later in the
project. One of the first things we would have realized was that the
whole thing could have been significantly smaller than it was. This
would have helped just by making things more manageable and
decreasing the weight of the turntable allowing it to turn more easily. It
would have made the project a lot easier if we had built everything such
that we could replace parts more easily, the turntable motor especially.
We really needed to replace the motor we were using with a much
slower one, but it was nearly impossible due to the poorly-thought-out
way that we had built the structure supporting it. This goes hand in hand
with another change we would make; choosing the right components the
first time around. We went through a number of motors for both the
turntable and the elevator without really testing them or doing any kind
of scientific analysis to determine which would be best

REFERNCES
19 | P a g e
https://www.tutorialspoint.com/c-program-for-tower-of-hanoi
https://en.wikipedia.org/wiki/Tower_of_Hanoi
https://en.wikipedia.org/wiki/Tower_of_Hanoi#Origins
https://en.wikipedia.org/wiki/Tower_of_Hanoi#Solution
https://en.wikipedia.org/wiki/Tower_of_Hanoi#Graphical_representatio
n

20 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy