Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. """
  2. A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps
  3. at a time.
  4. Implement a method to count how many possible ways the child can run up the stairs.
  5. """
  6. def staircase(num_stairs) :
  7. # base case
  8. if num_stairs < 0:
  9. return 0
  10. elif num_stairs == 1:
  11. return 1
  12. # otherwise, call the function recursively for each amount of steps the kiddo can take next
  13. else :
  14. return staircase(num_stairs-3) + staircase(num_stairs-2) + staircase(num_stairs-1)
  15.  
  16. print('6 stairs: ' + str(staircase(6)))
  17. print('20 stairs: ' + str(staircase(20)))
Add Comment
Please, Sign In to add comment