blob: 22d13118169ed0484f619132928a03f397099c9a (
plain)
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
|
from common import sieve
#
# WARNING: uses a lot of RAM!
#
# notes:
# - limit:1000000, sieve:50000000 -> no result when starting with ["3"] or ["7"]
# - limit:800000, sieve:50000000 -> no result!
# - limit:100000, sieve:100000000 -> [['13', '5197', '5701', '6733', '8389']]
#
#
limit = 9000
primes = sieve(int(str(limit)+str(limit))).primes()
prime_list = [ p for p in primes if p < limit]
prime_list.sort()
prime_list_str = [ str(p) for p in prime_list ]
def check_list(l):
result = []
for sublist in l:
for p in prime_list_str:
isprime = True
for n in sublist:
if int(n+p) not in primes or int(p+n) not in primes:
isprime = False
break
if isprime:
result += [ sublist+[p] ]
return result
def cleanup(l):
result = []
for sublist in l:
sublist.sort()
if sublist not in result:
result += [sublist]
return result
l = [ [p] for p in prime_list_str ]
for i in range(4):
l = cleanup(check_list(l))
print l
|