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...
icon
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.
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"""
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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…
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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY