-
Notifications
You must be signed in to change notification settings - Fork 0
/
35.py
75 lines (67 loc) · 1.31 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import math
import time
t1 = time.clock()
def isPrime (num):
ub = math.ceil(num**(1/2))
j = 3
while (j<=ub):
if (num%j == 0):
return False
j+=2
return True
def isPrimeT (num):
if (num <=1):
return False
if (num == 2 or num==3):
return True
elif (num%2 == 0):
return False
else:
ub = math.ceil(num**(1/2))
j = 3
while (j<=ub):
if (num%j == 0):
return False
j+=2
return True
def getCircularGen (num):
temp = str(num)
i = 0
while (i < len(temp)-1):
temp = temp[1:] + temp[0]
yield int(temp)
i+=1
array = [2,3,5,7]
for x in range (11,1000000,2):
if (isPrime(x)):
array.append(x)
t2 = time.clock()
print('Time to initialize array of primes:', t2 - t1)
def getTrueRotations (num):
rotations = getCircularGen(num)
tempExempt = [num]
for z in rotations:
if (isPrimeT(z)):
tempExempt.append(z)
else:
return False
return tempExempt
exempt = [2,3,5,7,11]
for y in array:
if (y not in exempt):
tempExempt = getTrueRotations(y)
if (tempExempt != False):
'''
rotations = getCircularGen(y)
tempExempt = [y]
for z in rotations:
if (isPrimeT(z)):
tempExempt.append(z)
'''
if (len(tempExempt) == len(str(y))):
for a in tempExempt:
exempt.append(a)
t3 = time.clock()
print('Time to check circular', t3 - t2)
print(len(exempt))
print(exempt)