Skip to content

Instantly share code, notes, and snippets.

@gudnm
Created August 23, 2016 22:25
Show Gist options
  • Save gudnm/30d0e1d920d4f05f04e895c2a995afa7 to your computer and use it in GitHub Desktop.
Save gudnm/30d0e1d920d4f05f04e895c2a995afa7 to your computer and use it in GitHub Desktop.
Project Euler problem #35
n = 1000000
primes = [False, False] + [True]*(n-2)
for i in range(2, int(n**0.5)+1):
if primes[i]:
primes[i*i::i] = [False] * len(primes[i*i::i])
def check_rotations(num):
s = str(num)
return all(primes[int((s+s)[i:i+len(s)])] for i in range(len(s)))
print(len([True for i in range(2, n) if (primes[i] and check_rotations(i))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment