-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe49.py
38 lines (30 loc) · 839 Bytes
/
e49.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
from primes import primes
primes = [x for x in primes(10000) if x > 1000]
def group_permutations():
intlists = [map(int,x) for x in map(str,primes)]
for l in intlists: l.sort()
inttups = map(tuple,intlists)
pairs = zip(inttups,primes)
perms_dict = dict()
for pair in pairs:
t,p = pair
if t in perms_dict:
perms_dict[t].append(p)
else:
perms_dict[t] = [p]
return (x for x in perms_dict.itervalues() if len(x) > 2)
def check(l):
if len(l) < 3:
return False
head = l[0]
tail = l[1:]
for perm in tail:
diff = perm - head
if perm + diff in tail:
return (head,perm,perm+diff)
return check(tail)
def answer():
sols = [check(x) for x in group_permutations() if check(x)]
return int(reduce(lambda x,y: x+y, map(str,sols[1])))
if __name__ == '__main__':
print answer()