Skip to content

Simple python script to replicate solving the tower of Hanoi puzzle

Notifications You must be signed in to change notification settings

kathleenazali/Towers-of-Hanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Tower of Hanoi

TL;DR: Simple python script to replicate solving the tower of Hanoi puzzle. A class exercise to demonstrate recursion in python. Since there are various variations in GitHub, I'm documenting mine here.

From Wikipedia: The Tower of Hanoi (also called The problem of Benares Temple[1] or Tower of Brahma or Lucas' Tower[2] and sometimes pluralized as Towers, or simply pyramid puzzle[3]) 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:[4]

Rules & objectives of the puzzle:

  • Only one disk may be moved at a time.
  • 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.
  • No disk may be placed on top of a disk that is smaller than it.
  • With three disks, the puzzle can be solved in seven moves.
  • The minimal number of moves required to solve a Tower of Hanoi puzzle is 2^n − 1, where n is the number of disks.

About

Simple python script to replicate solving the tower of Hanoi puzzle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages