![hanoi towers python hanoi towers python](https://www.askpython.com/wp-content/uploads/2021/06/STEP-1-300x109.png)
![hanoi towers python hanoi towers python](https://i.ytimg.com/vi/9kfXiMuBwUk/hqdefault.jpg)
![hanoi towers python hanoi towers python](https://i.ytimg.com/vi/jEa9Eokf2L8/maxresdefault.jpg)
The puzzle starts with the disks on the initial rod in a neat stack in ascending order of size (smallest at the top). def printHanoi(pegs):ĭisc = "-" * (0 if r>=len(peg) else peg) Towers of Hanoi consists of three rods and n number of disks of different sizes, which can be moved to any rod. You can then feed your movements to that function. This uses Steen Lumholts Tk interface from Tkinter import Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c. I am sure that the answer is pretty easy but my brain is running on the lowest setting right now. I tried several things like a while loop and for loops etc.
HANOI TOWERS PYTHON CODE
If you model your pegs as a list of lists with the larger discs at the lower indices, it should be relatively simple to implement a printing function and a movement function (that also prints). I have written a code for 'Towers of Hanoi' in python and I am trying to add a counter to show how many times it has run.