Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps
- at a time.
- Implement a method to count how many possible ways the child can run up the stairs.
- """
- def staircase(num_stairs) :
- # base case
- if num_stairs < 0:
- return 0
- elif num_stairs == 1:
- return 1
- # otherwise, call the function recursively for each amount of steps the kiddo can take next
- else :
- return staircase(num_stairs-3) + staircase(num_stairs-2) + staircase(num_stairs-1)
- print('6 stairs: ' + str(staircase(6)))
- print('20 stairs: ' + str(staircase(20)))
Add Comment
Please, Sign In to add comment