-
Notifications
You must be signed in to change notification settings - Fork 0
/
35.py
37 lines (32 loc) · 1008 Bytes
/
35.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
import math
def all_primes_under(num):
all_primes = []
for i in range(2, num):
is_prime = True
for possible_divisor in all_primes:
if i % possible_divisor == 0:
is_prime = False
break
if possible_divisor > math.sqrt(i):
break
if is_prime == True:
all_primes.append(i)
return all_primes
def circular_primes_under(num):
all_primes = set(all_primes_under(num))
circular_primes = set()
for prime in all_primes:
rotations = set(all_rotations(prime))
if rotations.issubset(all_primes):
circular_primes = circular_primes.union(rotations)
return circular_primes
def all_rotations(num):
stringified = str(num)
result = []
for i in range(len(stringified)):
result.append(int(stringified))
stringified = rotate(stringified)
return result
def rotate(s):
return s[1:] + s[0]
print len(circular_primes_under(1000000))