Re: My own accounting python euler problem

2009-11-08 Thread Ozz
for those duplicates, of course. On the other hand, I think viewing it as a powerset is the most 'natural' in this case. (imo permutations are about the order of objects, not about whether the objects are included in a set or not) cheers, Ozz -- http://mail.python.org/mailman/listinfo/python-list

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Dan Bishop schreef: You can avoid the S list my making it a generator: def subsets(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] Nice one. Thanks! Ozz -- http://mail.python.org/mailman/listinfo/python-list

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
al amounts correctly. I agree with you though that the term subset may not be the best name in this context because of those duplicates. cheers, Ozz -- http://mail.python.org/mailman/listinfo/python-list

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
Oops, For listing all different subsets of a list (This is what I came up with. Can it be implemented shorter, btw?): def subsets(L): S = [] if (len(L) == 1): return [L, []] better to check for the empty set too, thus; if (len(L) == 0): retur

Re: My own accounting python euler problem

2009-11-08 Thread Ozz
, 4], [8], [8, 4], [8, 7], [8, 7, 4]] >>> map(sum,subset.subsets([4,7,8,2])) [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] It's not a real solution yet, and as others have pointed out the problem is NP complete but it might help to get you going. cheers, Ozz -- h