Skip to content

Instantly share code, notes, and snippets.

@kentsalcedo
Created January 12, 2016 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentsalcedo/939ac172d5d54bf879ae to your computer and use it in GitHub Desktop.
Save kentsalcedo/939ac172d5d54bf879ae to your computer and use it in GitHub Desktop.
The Temple of Hanoi - Recursive morning challenge

##Tower Of Hanoi

According to legend, there is a temple in Hanoi where are located sixty-four golden rings of graduated sizes and three diamond towers. Each day, the monks of the temple move a ring from one tower to another according to the rule that only one ring may be moved each day, that a single move consists of taking the highest ring from one tower and placing it on another tower, and that no ring may be placed on top of a smaller ring. The rings and towers were placed at the beginning of the world, and the monks have toiled through the ages to move all the rings from the designated starting tower to the designated finishing tower, at each day making the move that minimizes the total number of moves required. The world will end when the monks complete their work.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

  1. Only one disk can 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 i.e. a disk can only be moved if it is the uppermost disk on a stack.

  3. No disk may be placed on top of a smaller disk.

Your task is to write a recursive program that calculates the sequence of moves that solved the Tower of Hanoi using the fewest number of moves.

'Tower of Hanoi Animated Solution'

Stretch Goal - If you finish early try to animate it on the DOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment