Created
March 2, 2011 06:09
-
-
Save rbreve/850541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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