Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def part(n):
- """Return the number of partitions of positive integer n.
- >>> part(5)
- 7
- >>> part(10)
- 42
- >>> part(15)
- 176
- >>> part(20)
- 627
- """
- def helper(ls, n):
- if n == 0:
- return 1
- if len(ls) == 0 or n < 0:
- return 0
- return helper(ls[1:], n) + helper(ls, n-ls[0])
- integers = []
- for i in range(n+1):
- if i > 0:
- integers.append(i)
- return helper(integers, n)
Add Comment
Please, Sign In to add comment