Output the number of combinations that add up to 10.
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def get_integral_value_combination(list, target):
def a(idx, l, r, t):
if t == sum(l): r.append(l)
elif t < sum(l): return
for u in range(idx, len(list)):
a((u + 1), l + [list[u]], r, t)
return r
return a(0, [], [], target)
print get_integral_value_combination(list, 10)
results
$ python test.py
[[1, 2, 3, 4], [1, 2, 7], [1, 3, 6], [1, 4, 5], [1, 9], [2, 3, 5], [2, 8], [3, 7], [4, 6], [10]]