-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_35.py
42 lines (37 loc) · 952 Bytes
/
problem_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
import numpy as np
import itertools
import time
limit= 10**6
def sieve(nums):
for x in range(0, int((limit**0.5)/2)):
nums[(nums!=nums[x]) & (nums % nums[x] == 0)] = 0
nums = nums[nums!=0]
return nums
def permify(nums):
answer = []
rotation = nums
while not rotation in answer:
answer.append(rotation)
rotation = int(str(rotation)[1:] + str(rotation)[0])
return answer
def num_circ(primes):
count = []
circ = True
for num in primes:
perms = permify(num)
for y in perms:
if y not in primes:
circ = False
primes = primes[primes!=y]
if circ:
count += perms
circ = True
return count
def problem_35():
start = time.time()
nums = np.arange(3, limit, 2, dtype=int)
primes = sieve(nums)
res = num_circ(primes)
print(res, len(res)+1)
print(time.time()-start)
problem_35()