Skip to content

Instantly share code, notes, and snippets.

@opethe1st
Created June 25, 2017 15:40
Show Gist options
  • Save opethe1st/38decbeb5837346485ed1ab0caf0233d to your computer and use it in GitHub Desktop.
Save opethe1st/38decbeb5837346485ed1ab0caf0233d to your computer and use it in GitHub Desktop.
solution = []
def possibleCombinations(N, items):
if N < 0:
return
if N == 0:
print solution
else:
for k in items:
key = k
v = items[key]
del items[k]
solution.append(key)
possibleCombinations(N - v, items)
solution.pop(-1)
items[k] = v
items = {"a": 23, "b": 34, "c": 36, "d": 64,
"e": 50, "f": 50, "g": 40, "h": 60}
possibleCombinations(100, items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment