Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Last active July 22, 2021 15:28
Show Gist options
  • Save igorvanloo/8074cf8da8ace2ed5bcbbd74b4e01fd2 to your computer and use it in GitHub Desktop.
Save igorvanloo/8074cf8da8ace2ed5bcbbd74b4e01fd2 to your computer and use it in GitHub Desktop.
Partition Function
def Partition(goal, alist):
ways = [0] + [1] * (goal)
for options in alist:
for i in range(len(ways) - options):
ways[i + options] += ways[i]
return ways[-1] #-1 here if you don't want to include 4 + 0 as a partition of 4 for example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment