Towers of Hanoi

The Towers of Hanoi is a puzzle that can be solved recursively.  The objective is to move the all of the discs one at a time from an arbitrary peg or 'tower' to another. Putting a larger disc over a smaller one must be avoided at all times and the transfer must be made in the least possible moves, which is equal to subtracting one from two raised to the number of discs.  Thus, the number of moves required for moving a stack of three discs is 2^3 - 1 or 7.  This script solves the Towers of Hanoi problem by moving a stack of 1 to a maximum of 8 discs from peg 1 to peg 3 with animation.  Enjoy!













No. of disks: