From the course: Python: Recursion
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Coding the Towers of Hanoi puzzle in Python - Python Tutorial
From the course: Python: Recursion
Coding the Towers of Hanoi puzzle in Python
- [Instructor] In the exercise files for chapter nine, video two we have a Python solution to the towers of Hanoi problem. Currently I've got my towers of Hanoi function wrapped in the helper function that we've looked at earlier in the course for getting verbose output so you can see what's going on with the recursion. It is temporary. I'm going to unwrap it just to keep things a little bit simpler when I first run it. So now the main function code is happening on nine 25. And let me just explain the role of these arguments because this can get a little bit confusing. So we're saying here that A C and B are the names of the rods. So when we do towers of Hanoi, n, A C B that means N is the number of discs we're going to move end discs from A to C. So from peg A to peg C using B. Now using can be a bit of a funny word because you're not necessarily using the empty peg. So you can just think of it as meaning…