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.

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
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: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.
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 0.
Move a disk from peg 2 to peg 1.
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 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 0 to peg 1.
Move a disk from peg 0 to peg 2.
Move a disk from peg 1 to peg 2.
Transcribed Image Text: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 0. Move a disk from peg 2 to peg 1. 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 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 0 to peg 1. Move a disk from peg 0 to peg 2. Move a disk from peg 1 to peg 2.
Expert Solution
Step 1

Computer Science homework question answer, step 1, image 1

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar 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