project-euler/105_special_subset_sums_tes...

22 lines
525 B
Python

#!/usr/bin/env python3
def test(s):
if len(s) != len(set(s)):
return False
s.sort()
if sum(s[:len(s)//2 + len(s)%2]) <= sum(s[len(s)//2+1:]):
return False
setsums = []
for n in s:
setsums += [m+n for m in setsums] + [n]
if len(setsums) != len(set(setsums)):
return False
return True
with open("data/105_sets.txt") as f:
r = f.read()
sets = [list(map(int, line.split(','))) for line in r.split('\n')[:-1]]
print(sum(sum(s) for s in sets if test(s)))