Tower of Hanoi: recursion, solved in 5 languages
recursion, moves, code
5 steps · about 52 min · Beginner
- Tower of Hanoi Problem - Made Easy (video, Abdul Bari, 10 min)
A classic algorithms teacher traces the recursion on a whiteboard.
- Towers of Hanoi: A Complete Recursive Visualization (video, Reducible, 21 min)
An animated "trust the recursion" explanation, and why it takes 2ⁿ−1 moves.
- Towers of Hanoi (article, Rosetta Code, 8 min)
The same task in 100+ languages; read the Python, JavaScript, Java, C++ and Go versions.
- TheAlgorithms/Python: tower_of_hanoi.py (repo, TheAlgorithms, 5 min)
Short, tested code from one of the most starred algorithm collections.
- Tower of Hanoi game (interactive, Math is Fun, 8 min)
Try 4 to 6 disks yourself and count the moves.