Skip to content
Fast implementation of the Hanoi Towers logic riddle
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitattributes
LICENSE
README.md
hanoi.py

README.md

Hanoi Towers

  1. Details

  2. How to use the Hanoi Tower algorithm implementation

  3. License

  4. Credits

1. Details

  • 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

2. How to use the Hanoi Tower algorithm implementation

2.1 Installation

Clone or download this repository, then open the folder. No additional dependencies are needed.

2.2 Usage

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]

3. License

The algorithm and the implementation are published under the MIT License.

4. Credits

The algorithm and the implementation are developed by Tim-Luca Lagmöller.

You can’t perform that action at this time.