Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. _MIN_SUM = 100
  2. _MAX_SUM = 200
  3. _MIN_NUM = 1
  4. _MAX_NUM = 49
  5. _NUM_CHOICES = 6
  6.  
  7. def f(n=_NUM_CHOICES, l=_MIN_NUM, s=0, cache={}):
  8. # Base case.
  9. if n == 0: return int(_MIN_SUM <= s <= _MAX_SUM)
  10.  
  11. key = (n, l, s)
  12. result = cache.get(key)
  13. if result is None:
  14. # Induction.
  15. result = sum(f(n-1, l=i+1, s=s+i) for i in xrange(l, _MAX_NUM+1))
  16. cache[key] = result
  17. return result
  18.  
  19. if __name__ == '__main__':
  20. print(f())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement