id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

tmhscs@gmail.com towers

████████╗ ██████╗ ██╗    ██╗███████╗██████╗      ██████╗ ███████╗    ██╗  ██╗ █████╗ ███╗   ██╗ ██████╗ ██╗
╚══██╔══╝██╔═══██╗██║    ██║██╔════╝██╔══██╗    ██╔═══██╗██╔════╝    ██║  ██║██╔══██╗████╗  ██║██╔═══██╗██║
   ██║   ██║   ██║██║ █╗ ██║█████╗  ██████╔╝    ██║   ██║█████╗      ███████║███████║██╔██╗ ██║██║   ██║██║
   ██║   ██║   ██║██║███╗██║██╔══╝  ██╔══██╗    ██║   ██║██╔══╝      ██╔══██║██╔══██║██║╚██╗██║██║   ██║██║
   ██║   ╚██████╔╝╚███╔███╔╝███████╗██║  ██║    ╚██████╔╝██║         ██║  ██║██║  ██║██║ ╚████║╚██████╔╝██║
   ╚═╝    ╚═════╝  ╚══╝╚══╝ ╚══════╝╚═╝  ╚═╝     ╚═════╝ ╚═╝         ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ ╚═╝
The Tower of Hanoi is a mathematical puzzle where there are three rods and a number of disks of different sizes.
The puzzle starts with all of the disks in a neat stack in size-order on one rod with the smallest at the top.
The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:

RULE #1. Only one disk can be moved at a time.
RULE #2. Each move must only take the top disk from a rod and place it onto another rod.
RULE #3. A larger disk must NOT be placed on top of a smaller disk.

Origin: The classical legend is about the Tower of Brahma in a temple in the Indian city of Benares.
The temple priests needed to move a tower of 64 fragile gold disks from one part of the temple to another.
Because of their fragility, a larger disk must never be placed on a smaller one.
Also, there was only one intermediate location where disks could be temporarily placed.
It is said that if the priests complete their task that the world will end.
If the legend is true and the priests were able to move disks at a rate of one per second,
using the smallest number of moves would take them roughly 585 billion years, so we are safe.

Play the game online using one of these links:

GAME #1. https://www.mathsisfun.com/games/towerofhanoi.html
GAME #2. https://www.mathplayground.com/logic_tower_of_hanoi.html
GAME #3. https://www.coolmathgames.com/0-tower-of-hanoi

Read about the algorithm to solve the game online using one of these links:

LINK #1. https://en.wikipedia.org/wiki/Tower_of_Hanoi
LINK #2. https://www.khanacademy.org/computing/computer-science/algorithms/towers-of-hanoi/a/towers-of-hanoi
LINK #3. https://www.cs.cmu.edu/~cburch/survey/recurse/hanoiimpl.html

Watch videos explaining the recursive solution, such as these:

VIDEO #1. RecursiveVisualization: https://www.youtube.com/watch?v=rf6uf3jNjbo
VIDEO #2. GeeksforGeeks Towers: https://www.youtube.com/watch?v=YstLjLCGmgg
VIDEO #3. Computerphile Towers: https://www.youtube.com/watch?v=8lhxIOAfDss

Solve the following codingbat question on the Tower of Hanoi!
███████████████████████████████
towerOfHanoi H   Tower of Hanoi █
███████████████████████████████

        ^     \    /      ^        
       / \    )\__/(     / \       
      /   \  (_\  /_)   /   \      
 ____/_____\__\@  @/___/_____\____ 
|             |\../|              |
|              \VV/               |
|  BEWARE: THIS QUESTION IS HARD  |
|  TAKE YOUR TIME AND RESEARCH!!  |
|_________________________________|
 |    /\ /      \\       \ /\    | 
 |  /   V        ))       V   \  | 
 |/     '       //        '     \| 
 '              V                '

Authoring docs

Copyright Nick Parlante 2017 - privacy