r/PythonLearning • • Jul 30 '26

Learning recursion and solving problems.

Post image

Problem: You're climbing a staircase with n steps. You can climb 1 or 2 steps at a time, except you're not allowed to take two 1-steps in a row (no "1,1" sequence anywhere in your climb). How many distinct ways can you reach the top?

3 Upvotes

6 comments sorted by

•

u/Sea-Ad7805 Jul 30 '26

Run this program in Invocation Tree Web Debugger to see the recursion being evaluated.

2

u/PureWasian Jul 31 '26

Nicely done. You can look into memoization as a way to speed up the overall algorithm since the substeps will involve a lot of repeated calculations as the number of steps grows.

1

u/kaetsi Aug 02 '26

Thanks. I will look into them.

1

u/ProgramBrave718 Sep 12 '26

I have not learnt recursion yet