Skip to content

Instantly share code, notes, and snippets.

@avegancafe
Created April 15, 2015 03:16
Show Gist options
  • Save avegancafe/0680525be4be488a5630 to your computer and use it in GitHub Desktop.
Save avegancafe/0680525be4be488a5630 to your computer and use it in GitHub Desktop.
def subsetsum(array,num):
if num == 0 or num < 1:
return None
elif len(array) == 0:
return None
else:
if array[0] == num:
return [array[0]]
else:
with_v = subsetsum(array[1:],(num - array[0]))
if with_v:
return [array[0]] + with_v
else:
return subsetsum(array[1:],num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment