Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, we will implement a class that can solve a three - pole Tower of Hanoi puzzle for any number of discs starting

In this project, we will implement a class that can solve a three-pole Tower of Hanoi puzzle for any number of discs starting from any source pole and going to any other destination pole. First, our class will do so recursively, and then it will do so recursively and efficiently.
TODO
Implement the Hanoi class in two stages.
Stage 1:
Implement the recursive solution.
Commit and push your work as you do so, committing at a minimum after each function definition.
Test drive your recursive implementation from src/main. cpp confirming correct solutions.
Commit and push your work.
Iterate as necessary, and commit and push your work throughout.
Commit and push successful program run(s) for stage 1.
Stage 2:
Memoize and optimize your solution.
Commit and push your work.
Test drive your memoized implementation from src/main. cpp .
Commit and push your work.
Run unit tests.
Iterate as necessary, and commit and push your work throughout.
Commit and push successful program run(s) for stage 2. Solution output will of course be identical to stage 1.
Add a "Project 02 Complete" comment to your Feedback pull request.
Give yourself yet another high five!
Stage 1
std::string Hanoi: solve(int num_discs, int src, int dst, int tmp)
This is the one and only public member function of the Hanoi class. It represents the user interface.
The user will call solve() and provide the number of discs ( num_discs ) they would like to move from the source pole ( src ) to the destination pole (dst ) using the third pole as a temporary pole (tmp).
solve() returns a string representation of the necessary moves preceded by the following line:
# Below, 'A B' means 'move the top disc on pole A to pole B
solve() will supply this line and then add to it the string solution provided by calling get_moves ().
For example, calling solve (2,1,2,3) would ultimately return the string:
# Below, 'A B' means 'move the top disc on pole A to pole B
13
12
32
std: :string Hanoi: :get_moves(int num_discs, int src, int dst, int tmp)
get_moves() returns the string representation of the required moves to move num_discs discs from the src pole to the dst pole using the tmp pole as a temporary pole.
Each move will be on its own line.
For example, get_moves (2,1,2,3) would return the string:
13
12
32
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions