euler/python/e035.py

26 lines
504 B
Python
Raw Normal View History

2019-07-16 18:51:07 +02:00
from lib_prime import primes
def cyles(xs):
if len(xs) <= 1:
return xs
return [xs[i:] + xs[:i] for i in range(len(xs))]
def is_circular(p, prime_set):
cs = cyles(str(p))
for c in cs:
if not int("".join(c)) in prime_set:
return False
return True
def euler_035():
ps = set(primes(1000000))
return len([p for p in ps if is_circular(p, ps)])
if __name__ == "__main__":
print("e035.py: {}".format(euler_035()))
assert(euler_035() == 55)