Question: Write a function to solve the Tower of Hanoi problem. The function should take in the number of discs and the names of three towers,
Write a function to solve the Tower of Hanoi problem. The function should take in the number of discs and the names of three towers, and return the steps required to move all the discs from the first tower to the third tower. The function should first use recursion to solve the problem and then return the list of steps.
Example:
Input:
num_discs = 3
tower1 = "Tower 1"
tower2 = "Tower 2"
tower3 = "Tower 3"
Output: [
("Tower 1", "Tower 3"),
("Tower 1", "Tower 2"),
("Tower 3", "Tower 2"),
("Tower 1", "Tower 3"),
("Tower 2", "Tower 1"),
("Tower 2", "Tower 3"),
("Tower 1", "Tower 3")
]
Step by Step Solution
3.38 Rating (154 Votes )
There are 3 Steps involved in it
The detailed ... View full answer
Get step-by-step solutions from verified subject matter experts
