-
Details
-
How to use the Hanoi Tower algorithm implementation
-
License
-
Credits
-
The Tower of Hanoi is a logic game in which you need to transfer disks from one rod to another with special rules
-
This algorithm is easy to implement as a recursive function, but this would be highly space-inefficient
-
I came up with an algorithm which solves the Towers of Hanoi without any recursive functions, which effects in much better space- and time-efficiency
Clone or download this repository, then open the folder. No additional dependencies are needed.
First, you need to import hanoi:
import hanoi
If you just want to output the steps needed to solve the Towers of Hanoi with n disks, type this: (Example: n=6)
n = 6
hanoi.output(n)
If you want to get the disk's order and movement as a list, you have to enter this code snippet:
n = 6
order = generate_order(n)
movement = generate_movement(n)
# In this example, the disk order[i] must be moved to the rod movement[i]
The algorithm and the implementation are published under the MIT License.
The algorithm and the implementation are developed by Tim-Luca Lagmöller.
I'm part of the official GitHub Sponsors program where you can support me on a monthly basis.
You can also contribute by buying me a coffee (this is a one-time donation).
Thank you for your support!