-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path60.py
53 lines (43 loc) · 1.18 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
n = 10000 ## this takes around 3 minutes!!!! without precalculation of primes below
PRIME = [True] * 100000000
PRIME[0] = PRIME[1] = False
for i in range(int(100000000**0.5)+2):
if PRIME[i]:
for j in range(i*i, 100000000, i):
PRIME[j] = False
def is_prime_l(l, n):
def front(e, n):
return int(str(n)+str(e))
def back(e, n):
return int(str(e)+str(n))
if n in l:
return False
for e in l:
if (not is_prime(front(e, n)) or
not is_prime(back(e, n))):
return False
return True
def prime_prop(primes, l, n):
nl = []
sum_seen = set()
while (len(l[0]) < n):
for e in l:
for prime in primes:
if is_prime_l(e, prime):
ne = e + [prime]
if sum(ne) not in sum_seen:
sum_seen.add(sum(ne))
nl.append(ne)
l = nl
print(l)
nl = []
return l
def is_prime(n):
return PRIME[n]
primes = []
primes_l = []
for i in range(n):
if PRIME[i]:
primes.append(i)
primes_l.append([i])
res = prime_prop(primes, primes_l, 5)