-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path51.py
45 lines (38 loc) · 923 Bytes
/
51.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
from euler import isPrime, primes
from itertools import combinations
def getCombinations(num):
lista=range(len(str(num)))
ret=[]
for L in range(1, len(lista)+1):
for subset in combinations(lista, L):
ret.append(subset)
return ret
def numPrimes(lista):
return len([x for x in lista if isPrime(x)])
def getReplaced(num):
ret=[]
for c in getCombinations(num):
ret.append(replace(num,c))
return ret
def replace(num,pos):
ret=[]
if 0 in pos:
lista=range(1,10)
else:
lista=range(10)
for n in lista:
aux=list(str(num))
for p in pos:
aux[p]=str(n)
ret.append(int(''.join(aux)))
return ret
for p in primes(10**6):
stop=False
for l in getReplaced(p):
if numPrimes(l)==8:
print l
stop=True
break
if stop:
break
#121313