-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheuler-105.py
43 lines (38 loc) · 869 Bytes
/
euler-105.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import with_statement
import psyco
psyco.full()
def powerset(s) :
length = len(s)
for i in xrange(1, 1 << length) :
yield [c for j, c in enumerate(s) if (1 << j) & i]
return
def isSpecialSet(s) :
for i in xrange(1,1+len(s)/2) :
left, right = s[:i+1], s[-i:]
if len(left) <= len(right) :
break
if sum(left) <= sum(right) :
print left, right
return False
sset = set(s)
for a in powerset(s) :
diff = sset - set(a)
suma = sum(a)
for b in powerset(diff) :
if suma == sum(b) :
print suma, sorted(a), sorted(b)
return False
return True
def test() :
total = 0
with open("sets-105.txt") as f :
for line in f :
print "-----"
a = sorted(int(d) for d in line.strip().split(","))
if isSpecialSet(a) :
#print "Special: ", a
total += sum(a)
else :
print "Not special: ", a
print total
test()