Towers of Hanoi. There is a story about Buddhist monks who are playing this puzzle with 64 stone disks. The story claims that when the monks finish moving the disks from one post to a second via the third post, time will end. Eschatology (concerns about the end of time) and theology will be left to those better qualified; our interest is limited to the recur- sive solution to the problem.   A stack of n disks of decreasing size is placed on one of three posts. The task is to move the disks one at a time from the first post to the second. To do this, any disk can be moved from any post to any other post, subject to the rule that you can never place a larger disk over a smaller disk. The (spare) third post is provided to make the solution possible. Your task is using c++ write a recursive function that describes instructions for a solution to this problem. We don’t have graphics available, so you should output a sequence of instructions that will solve the problem.   Hint: If you could move n-1 of the disks from the first post to the third post using the second post as a spare, the last disk could be moved from the first post to the second post. Then by using the same technique (whatever that may be) you can move the n-1 disks from the third post to the second post, using the first disk as a spare. There! You have the puzzle solved. You only have to decide what the non-recursive case is, what the recursive case is, and when to output instructions to move the disks.   I am expecting to see the following sample output from a run of this program: RUN 1: TOWERS of Hanoi Enter a number of disks to play. I'll give necessary moves. 3 Move a disk from post A to post B Move a disk from post A to post C Move a disk from post B to post C Move a disk from post A to post B Move a disk from post C to post A Move a disk from post C to post B Move a disk from post A to post B Process returned 0 (0x0) execution time : 4.788 s Press any key to continue. ------------------------------------------ RUN 2 TOWERS of Hanoi Enter a number of disks to play. I'll give necessary moves. 4 Move a disk from post A to post C Move a disk from post A to post B Move a disk from post C to post B Move a disk from post A to post C Move a disk from post B to post A Move a disk from post B to post C Move a disk from post A to post C Move a disk from post A to post B Move a disk from post C to post B Move a disk from post C to post A Move a disk from post B to post A Move a disk from post C to post B Move a disk from post A to post C Move a disk from post A to post B Move a disk from post C to post B

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Towers of Hanoi.

There is a story about Buddhist monks who are playing this puzzle with

64 stone disks. The story claims that when the monks finish moving the disks from one

post to a second via the third post, time will end. Eschatology (concerns about the end of

time) and theology will be left to those better qualified; our interest is limited to the recur-

sive solution to the problem.

 

A stack of n disks of decreasing size is placed on one of three posts. The task is to move the

disks one at a time from the first post to the second. To do this, any disk can be moved

from any post to any other post, subject to the rule that you can never place a larger disk

over a smaller disk. The (spare) third post is provided to make the solution possible. Your

task is using c++ write a recursive function that describes instructions for a solution to this problem. We don’t have graphics available, so you should output a sequence of instructions

that will solve the problem.

 

Hint:

If you could move n-1 of the disks from the first post to the third post using the

second post as a spare, the last disk could be moved from the first post to the second post.

Then by using the same technique (whatever that may be) you can move the

n-1 disks

from the third post to the second post, using the first disk as a spare. There! You have the

puzzle solved. You only have to decide what the non-recursive case is, what the recursive case

is, and when to output instructions to move the disks.

 

I am expecting to see the following sample output from a run of this program:

RUN 1:

TOWERS of Hanoi
Enter a number of disks to play. I'll give necessary moves.
3
Move a disk from post A to post B
Move a disk from post A to post C
Move a disk from post B to post C
Move a disk from post A to post B
Move a disk from post C to post A
Move a disk from post C to post B
Move a disk from post A to post B

Process returned 0 (0x0) execution time : 4.788 s
Press any key to continue.

------------------------------------------

RUN 2

TOWERS of Hanoi
Enter a number of disks to play. I'll give necessary moves.
4
Move a disk from post A to post C
Move a disk from post A to post B
Move a disk from post C to post B
Move a disk from post A to post C
Move a disk from post B to post A
Move a disk from post B to post C
Move a disk from post A to post C
Move a disk from post A to post B
Move a disk from post C to post B
Move a disk from post C to post A
Move a disk from post B to post A
Move a disk from post C to post B
Move a disk from post A to post C
Move a disk from post A to post B
Move a disk from post C to post B

 

 

NOTE: DONT USE CHEGG

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education