Write a Python program that solves the Towers of Hanoi puzzle. Your program should ask the user for the number of disks to be moved then it should list the moves that need to be done for a complete solution. Here is output from a sample run. How many pegs do you want to start with? --> 4 Move a disk from peg e to peg 1. Move a disk from peg e to peg 2. Move a disk from peg 1 to peg 2. Move a disk from peg e to peg 1. Move a disk from peg 2 to peg e. Move a disk from peg 2 to peg 1. Move a disk from peg e to peg 1. Move a disk from peg 0 to peg 2. Move a disk from peg 1 to peg 2. Move a disk from peg 1 to peg e. Move a disk from peg 2 to peg e. Move a disk from peg 1 to peg 2. Move a disk from peg e to peg 1. Move a disk from peg e to peg 2. Move a disk from peg 1 to peg 2. Your program must conform to the following specifications! 1) Represent the three pegs and disks as a three element list called board, where boardſij is the number of disks currently on peg i. Thus, the initial position would have board = [n, 0, 0]. 2) Have a function named move that is passed the board, the index of the peg a disk is to be moved from, and the index of the peg the disk is to be moved to then transfers the top disk betweem the given pegs and prints the move. 3) Have a function named getOther that is passed the indices of two pegs and returns the index of the other peg
Write a Python program that solves the Towers of Hanoi puzzle. Your program should ask the user for the number of disks to be moved then it should list the moves that need to be done for a complete solution. Here is output from a sample run. How many pegs do you want to start with? --> 4 Move a disk from peg e to peg 1. Move a disk from peg e to peg 2. Move a disk from peg 1 to peg 2. Move a disk from peg e to peg 1. Move a disk from peg 2 to peg e. Move a disk from peg 2 to peg 1. Move a disk from peg e to peg 1. Move a disk from peg 0 to peg 2. Move a disk from peg 1 to peg 2. Move a disk from peg 1 to peg e. Move a disk from peg 2 to peg e. Move a disk from peg 1 to peg 2. Move a disk from peg e to peg 1. Move a disk from peg e to peg 2. Move a disk from peg 1 to peg 2. Your program must conform to the following specifications! 1) Represent the three pegs and disks as a three element list called board, where boardſij is the number of disks currently on peg i. Thus, the initial position would have board = [n, 0, 0]. 2) Have a function named move that is passed the board, the index of the peg a disk is to be moved from, and the index of the peg the disk is to be moved to then transfers the top disk betweem the given pegs and prints the move. 3) Have a function named getOther that is passed the indices of two pegs and returns the index of the other peg
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![Assignment
Write a Python program that solves the Towers of Hanoi puzzle.
Your program should ask the user for the number of disks to be moved then it should list the moves that need to be done for a complete solution.
Here is output from a sample run.
How many pegs do you want to start with? --> 4
Move a disk from peg 0 to peg 1.
Move a disk from peg 0 to peg 2.
Move a disk from peg 1 to peg 2.
Move a disk from peg 0 to peg 1.
Move a disk from peg 2 to peg e.
Move a disk from peg 2 to peg 1.
Move a disk from peg 0 to peg 1.
Move a disk from peg e to peg 2.
Move a disk from peg 1 to peg 2.
Move a disk from peg 1 to peg 0.
Move a disk from peg 2 to peg 0.
Move a disk from peg 1 to peg 2.
Move a disk from peg e to peg 1.
Move a disk from peg e to peg 2.
Move a disk from peg 1 to peg 2.
Your program must conform to the following specifications!
1) Represent the three pegs and disks as a three element list called board, where boardſi] is the number of disks currently on peg i. Thus, the initial position
would have board = [n, 0, 0].
2) Have a function named move that is passed the board, the index of the peg a disk is to be moved from, and the index of the peg the disk is to be moved to
then transfers the top disk betweem the given pegs and prints the move.
3) Have a function named getOther that is passed the indices of two pegs and returns the index of the other peg.
4) And most importantly, a function named solveTOH that is passed the board, the number of pegs, the from peg, and the to peg which performs the recursion
and calls move.
5) Your main program shoudl prompt the user for the number of disks, set up the board, and call solveTOH.
Here are some function headers to get you started.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa74b6a8e-f1b7-4d29-84ad-edc51d36ecf1%2F05c407c5-fe2e-498b-9991-425cb254dbd3%2Fd0wlnf_processed.png&w=3840&q=75)
Transcribed Image Text:Assignment
Write a Python program that solves the Towers of Hanoi puzzle.
Your program should ask the user for the number of disks to be moved then it should list the moves that need to be done for a complete solution.
Here is output from a sample run.
How many pegs do you want to start with? --> 4
Move a disk from peg 0 to peg 1.
Move a disk from peg 0 to peg 2.
Move a disk from peg 1 to peg 2.
Move a disk from peg 0 to peg 1.
Move a disk from peg 2 to peg e.
Move a disk from peg 2 to peg 1.
Move a disk from peg 0 to peg 1.
Move a disk from peg e to peg 2.
Move a disk from peg 1 to peg 2.
Move a disk from peg 1 to peg 0.
Move a disk from peg 2 to peg 0.
Move a disk from peg 1 to peg 2.
Move a disk from peg e to peg 1.
Move a disk from peg e to peg 2.
Move a disk from peg 1 to peg 2.
Your program must conform to the following specifications!
1) Represent the three pegs and disks as a three element list called board, where boardſi] is the number of disks currently on peg i. Thus, the initial position
would have board = [n, 0, 0].
2) Have a function named move that is passed the board, the index of the peg a disk is to be moved from, and the index of the peg the disk is to be moved to
then transfers the top disk betweem the given pegs and prints the move.
3) Have a function named getOther that is passed the indices of two pegs and returns the index of the other peg.
4) And most importantly, a function named solveTOH that is passed the board, the number of pegs, the from peg, and the to peg which performs the recursion
and calls move.
5) Your main program shoudl prompt the user for the number of disks, set up the board, and call solveTOH.
Here are some function headers to get you started.
![5) Your main program shoudl prompt the user for the number of disks, set up the board, and call solve TOH.
Here are some function headers to get you started.
In [ ]: def move (board, fp, tp):
"""Moves the top disk from peg 'fp' to peg 'tp' in the given 'board'."""
In [ ]: def getother(fp, tp):
"""Returns the index of the peg not passed"""
In [ ]: def solveTOH(board, n, fp, tp):
"""Recusive solver"""](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa74b6a8e-f1b7-4d29-84ad-edc51d36ecf1%2F05c407c5-fe2e-498b-9991-425cb254dbd3%2Fmav5cuv_processed.png&w=3840&q=75)
Transcribed Image Text:5) Your main program shoudl prompt the user for the number of disks, set up the board, and call solve TOH.
Here are some function headers to get you started.
In [ ]: def move (board, fp, tp):
"""Moves the top disk from peg 'fp' to peg 'tp' in the given 'board'."""
In [ ]: def getother(fp, tp):
"""Returns the index of the peg not passed"""
In [ ]: def solveTOH(board, n, fp, tp):
"""Recusive solver"""
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY