-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path#37.py
More file actions
31 lines (26 loc) · 714 Bytes
/
#37.py
File metadata and controls
31 lines (26 loc) · 714 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
from math import sqrt
from itertools import count, islice
def isPrime(num_list):
for num in num_list:
n = int(num)
if n < 2 or n % 2 == 0 and n != 2:
return False
for i in islice(count(3, 2), int(sqrt(n)-1)//2):
if n % i == 0:
return False
return True
def all_subs(num):
str_num = str(num)
all_substrings = set()
for i in range(len(str_num)):
all_substrings.add(str_num[i:])
all_substrings.add(str_num[:i])
all_substrings.remove('')
return all_substrings
counter, sum_, num = 0, 0, 11
while counter < 11:
if isPrime(all_subs(num)):
sum_ += num
counter += 1
num += 2
print sum_