-
Notifications
You must be signed in to change notification settings - Fork 0
/
p60.py
48 lines (41 loc) · 1.34 KB
/
p60.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
44
45
46
47
from math import log10
from itertools import islice
from eulertools import primes, isprime
memo = {}
def testconcat(p,q):
p, q = primes[p], primes[q]
if (p,q) in memo: return memo[(p,q)]
if not isprime((10**int(1+log10(p)))*q+p, primes) or \
not isprime((10**int(1+log10(q)))*p+q, primes):
r = False
else:
r = True
memo[(p,q)] = r
return r
def testconcats(*ps):
testers, testee = ps[:-1], ps[-1]
return all(testconcat(tester, testee) for tester in testers)
def getfive():
i = 3
while True:
i += 1
for j in range(i-1, 3, -1):
if not testconcats(i, j):
continue
for k in range(j-1, 2, -1):
if not testconcats(i, j, k):
continue
for l in range(k-1, 1, -1):
if not testconcats(i, j, k, l):
continue
for m in range(l-1, 0, -1):
if not testconcats(i, j, k, l,
m):
continue
yield (i, j, k, l, m)
if __name__ == '__main__':
sums = []
for x in getfive():
sums.append(sum(primes[i] for i in x))
break # we'll just make an assumption...
print min(sums)