Write a function to solve the Tower of Hanoi problem. The function should take in the number
Fantastic news! We've Found the answer you've been seeking!
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, 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")
]
Related Book For
Data Structures And Algorithms In C++
ISBN: 9780470383278
2nd Edition
Authors: Michael T. Goodrich, Roberto Tamassia, David M. Mount
Posted Date: