Last active
July 22, 2021 15:28
-
-
Save igorvanloo/8074cf8da8ace2ed5bcbbd74b4e01fd2 to your computer and use it in GitHub Desktop.
Partition Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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