Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Solving 76, thanks @akrito for the suggestion to memoize

  • Loading branch information...
commit d352114a28cd6241f83f8587f61ce1d66c34598c 1 parent d10c0af
@coleifer authored
Showing with 21 additions and 0 deletions.
  1. +21 −0 problem76.py
View
21 problem76.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+def memo(fn):
+ _memo = {}
+ def inner(k, n):
+ tup = (k, n)
+ if tup not in _memo:
+ _memo[tup] = fn(k, n)
+ return _memo[tup]
+ return inner
+
+@memo
+def p(k, n):
+ if k > n:
+ return 0
+ if k == n:
+ return 1
+ return p(k+1, n) + p(k, n-k)
+
+# subtract 1 since we don't count n + 0
+print p(1, 100) - 1
Please sign in to comment.
Something went wrong with that request. Please try again.