So I want to print out all the subsets of the initial set that will add up to 21. So far I've only come up with this
def twentyone(array, num=21):
if len(array) == 0:
return None
else:
if array[0] == num:
return [array[0]]
else:
with_v = twentyone(array[1:], (num - array[0]))
if with_v:
return [array[0]] + with_v
else:
return twentyone(array[1:], num)
It does give the solution, but only the first. How do I change it so that it will give me every possible subset. I've tried making a few changes but it only gives me nested lists. Any help would be nice.