Skip to content

Instantly share code, notes, and snippets.

@rbreve
Created March 2, 2011 06:09
Show Gist options
  • Save rbreve/850541 to your computer and use it in GitHub Desktop.
Save rbreve/850541 to your computer and use it in GitHub Desktop.
lista=[3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99]
n=0
def powerset(seq):
if len(seq):
head = powerset(seq[:-1])
return head + [item + [seq[-1]] for item in head]
else:
return [[]]
def funcsort(seq, func):
seq = seq[:]
seq.sort(lambda x, y: cmp(func(x), func(y)))
return seq
power_set=powerset(lista)
pset=funcsort(power_set, lambda x: len(x))
for p in pset:
if sum(p) in lista and len(p) > 1:
n+=1
print n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment