SHARE
TWEET

Untitled

a guest Jun 15th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top