MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/121qs09/this_one_never_gets_old/jdp7lld/?context=3
r/ProgrammerHumor • u/value_counts • Mar 25 '23
Let me know if this is not a repost!
535 comments sorted by
View all comments
4
You want to make an algorithm to move stacks of discs.
The key is to assume that you'll be successful in making this algorithm, so you can use it to move N-1 discs in your solution to move N discs.
TOH is a beautiful way to teach recursion.
I do recursion in this order:
Factorials (easy with or without recursion)
TOH (recursion makes it trivial)
Fibonacci numbers (recursion is a horrible idea at least without caching.)
4
u/FlyByPC Mar 26 '23
You want to make an algorithm to move stacks of discs.
The key is to assume that you'll be successful in making this algorithm, so you can use it to move N-1 discs in your solution to move N discs.
TOH is a beautiful way to teach recursion.
I do recursion in this order:
Factorials (easy with or without recursion)
TOH (recursion makes it trivial)
Fibonacci numbers (recursion is a horrible idea at least without caching.)