Skip to content

suranwarnakulasooriya/Tower_of_Hanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Tower of Hanoi

A Python program that solves the Tower of Hanoi problem for 3 to 12 disks and animates the solution.

Dependencies

Assuming you have Python3 already, pygame, colour, and tkinter should be the only dependencies not automatically installed. They can all be installed with pip.

pip install pygame
pip install colour
pip install tkinter

Usage

When running the program, a tkinter window opens first. Here you can change the number of disks using the arrow buttons. The number of disks can be between 3 and 12 inclusive. Check the color box to give color to the disks, otherwise all of the disks are white (the sole use of the colour library is to interpolate the colors based on the number of disks). When ready, press the start button. The program computes all of the neccesary moves before the pygame window opens. Since the number of moves is equal to 2n-1, the number of moves that the program calculates ranges from 7 to 4095. While the animation runs, you can change the delay and by proxy the speed of the animation using the up and down arrow keys (up is faster and down is slower). The number of disks, number of moves, and delay are shown in the window title.

3 8

About

A Python program that solves the Tower of Hanoi problem for 3 to 12 disks and animates the solution.

Topics

Resources

License

Stars

Watchers

Forks

Languages