matacoder

Untitled

Dec 14th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. person = int(input())
  2.  
  3.  
  4. def get_commits(person, dict={}):
  5.     # print(f'Starting with {person}')
  6.     if person == 0:
  7.         return 1
  8.     elif person == 1:
  9.         return 1
  10.     elif person > 1:
  11.         # print(f'Get person {person - 1} and {person - 2}')
  12.         if person not in dict:
  13.             first = get_commits(person - 2, dict)
  14.             dict[person - 2] = first
  15.             second = get_commits(person - 1)
  16.             dict[person - 1] = second
  17.             sum = first + second
  18.             dict[person] = sum
  19.         else:
  20.             sum = dict[person]
  21.         return sum
  22.  
  23. print(get_commits(person))
Advertisement
Add Comment
Please, Sign In to add comment