-
Notifications
You must be signed in to change notification settings - Fork 0
/
p37.py
51 lines (46 loc) · 1.14 KB
/
p37.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
#!/usr/bin/python
import utils
primes = utils.FastPrimeSieve(1000000)
def truncatable(n):
global primes
buf = n
trunc = True
while buf > 10:
buf = utils.truncate_right(buf)
if buf not in primes:
trunc = False
break
if trunc == True:
buf = n
while buf > 10:
buf = utils.truncate_left(buf)
if buf not in primes:
trunc = False
break
return trunc
else:
return False
def truncatables(primes):
t = []
for prime in primes:
buf = prime
trunc = True
while buf > 10:
buf = utils.truncate_right(buf)
if buf not in primes:
trunc = False
break
if trunc == True:
buf = prime
while buf > 10:
buf = utils.truncate_left(buf)
if buf not in primes:
trunc = False
break
if trunc:
t.append(prime)
if len(t) > 14:
return t
if __name__ == "__main__":
t = truncatables(primes)
print sum(t[4:])