-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem37.py
More file actions
45 lines (36 loc) · 1000 Bytes
/
Problem37.py
File metadata and controls
45 lines (36 loc) · 1000 Bytes
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 Functions import IsPrime
def Solve():
TruncPrimes = []
def Possible(n):
digs = [int(x) for x in str(n)[1:]]
evens = [z for z in digs if z % 2 == 0]
if len(evens) > 0:
return(False)
elif 5 in digs:
return(False)
return(True)
def left(n):
while len(str(n)) > 1:
if n in TruncPrimes:
return True
if not IsPrime(n):
return(False)
n = int(str(n)[1:])
return(IsPrime(n))
def right(n):
while len(str(n)) > 1:
if n in TruncPrimes:
return True
if not IsPrime(n):
return(False)
n = int(str(n)[:-1])
return(IsPrime(n))
n = 21
while len(TruncPrimes) < 11:
if Possible(n):
if left(n) and right(n):
TruncPrimes += [n]
n += 2
return(sum(TruncPrimes))
if __name__ == '__main__':
print(Solve())