-
Notifications
You must be signed in to change notification settings - Fork 0
/
60.py
52 lines (40 loc) · 1.56 KB
/
60.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
48
49
50
51
52
from tools.collections import mil_primes, bil_primes
from tools.primes import is_prime
import numpy as np
'''
it took 4 mins. idk if it counts
'''
thousands = mil_primes[mil_primes<10000]
thousands = thousands.astype(str)
print("begin pairs")
pairs = []
for i in range(thousands.size):
for j in range(i, thousands.size):
a = thousands[i]
b = thousands[j]
if is_prime(int(a + b)) and is_prime(int(b + a)):
pairs.append((a,b))
print("Begin triplets")
triplets = []
for i in thousands:
for p in pairs:
if is_prime(int(i + p[0])) and is_prime(int(p[0] + i)) and is_prime(int(i + p[1])) and is_prime(int(p[1] + i)):
if i not in p:
triplets.append((p[0], p[1], i))
print("begin quadruplets")
quads = []
for i in thousands:
for p in triplets:
if is_prime(int(i + p[0])) and is_prime(int(p[0] + i)) and is_prime(int(i + p[1])) and is_prime(int(p[1] + i)):
if is_prime(int(i + p[2])) and is_prime(int(p[2] + i)) and i not in p:
quads.append((p[0], p[1], p[2], i))
print("begin pentuplets")
pentas = []
for i in thousands:
for p in quads:
if is_prime(int(i + p[0])) and is_prime(int(p[0] + i)) and is_prime(int(i + p[1])) and is_prime(int(p[1] + i)):
if is_prime(int(i + p[2])) and is_prime(int(p[2] + i)) and i not in p and is_prime(int(i + p[3])) and is_prime(int(p[3] + i)):
pentas.append((p[0], p[1], p[2], p[3], i))
answer = [[int(i) for i in b] for b in pentas]
answer = sorted(answer, key=sum)
print(sum(answer[0]), answer[0])