-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler35.py
More file actions
34 lines (21 loc) · 780 Bytes
/
Copy patheuler35.py
File metadata and controls
34 lines (21 loc) · 780 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
'''
Circular primes
Problem 35
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
'''
import math
from eulerlibrary import *
maxnumber = 1000000
primes = set(primes_to(maxnumber))
def rotate_number(number):
a = str(number)
return [a[i:] + a[:i] for i in range(len(a))]
def is_circular_prime(number):
return all([int(x) in primes for x in rotate_number(str(number))])
circular_primes_found = 0
for number in primes:
if is_circular_prime(number):
circular_primes_found += 1
print("Solution to Euler # 35 is: {}.".format(circular_primes_found))