Skip to content

AntonisParaskevis/hanoi-towers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hanoi-towers

A Python script that solves the Hanoi Towers puzzle.

About

From Wikipedia:

The Tower of Hanoi (also called The problem of Benares Temple, Tower of Brahma or Lucas's Tower, and sometimes pluralized as Towers, or simply pyramid puzzle) is a mathematical game or puzzle consisting of three rods and a number of disks of various diameters, which can slide onto any rod. The puzzle begins with the disks stacked on one rod in order of decreasing size, the smallest at the top, thus approximating a conical shape. The objective of the puzzle is to move the entire stack to one of the other rods, obeying the following rules:

  1. Only one disk may be moved at a time.
  2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
  3. No disk may be placed on top of a disk that is smaller than it.

Requirements

Python 3.x

Download

Click the Code button, then click on "Download ZIP"

OR

Click the Hanoi Towers.py file, then click on the Download Raw File button.

How to Use

  1. Enter the number of disks. It must be a positive integer. Then, press Enter.
  2. Enter the name of the starting peg. Then, press Enter.
  3. Enter the name of the destination peg. Then, press Enter.
  4. Enter the name of the auxiliary peg. Then, press Enter.
  5. The steps for solving the puzzle will be displayed on screen.
  6. Finally, press Enter to exit the program.

License

MIT License © 2025 Antonis Paraskevis