-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37.py
More file actions
43 lines (32 loc) · 713 Bytes
/
37.py
File metadata and controls
43 lines (32 loc) · 713 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
#!/usr/bin/env python3
# Searches for primes that remain prime under both left and right truncation.
"""Project Euler Problem 37: https://projecteuler.net/problem=37"""
import math
from collections import defaultdict
import sympy
ans = 0
my_dict = defaultdict(bool)
i = 11
sum = 0
while True:
var = str(i)
flag = True
while var:
if not sympy.isprime(int(var)):
flag = False
break
var = var[1:]
var = str(i)
while var:
if not sympy.isprime(int(var)):
flag = False
break
var = var[:-1]
if flag:
print(i)
sum += i
ans += 1
if ans == 11:
break
i += 1
print(sum)