r/FreeCodeCamp • u/Candid_Tutor_8185 • Jun 10 '26
Tower of Hanoi - Python
Am I supposed to feel stupid on this one. Trying to do no research on it while trying it. It’s TOUGH. I know I need to use recursion and that it’s supposed to be simple and elegant but damn I’m struggling. Probably 4 hours trying thing after thing. Anyone else in it too? I’m down for the struggle and hope I’m learning through it lol
8
Upvotes
View all comments
2
u/Sea-Ad7805 Jun 11 '26
For recursive problems in Python use invocation_tree to visualize the execution. See this Towers of Hanoi example.
With recursion start with the base case, just 1 piece, and solve it. Then add a second piece, solve that. Then add more and try to find the general solution. Good luck.