view problem35.py @ 13:836a4ccbcbae

#35 solution
author Dominic Cleal <dominic@computerkb.co.uk>
date Mon, 01 Dec 2008 13:14:53 +0000
parents
children
line wrap: on
line source

import primes

def rotate(ps):
	return ps[1:] + ps[0]

def testrotate(p):
	ps = str(p)
	for r in range(1, len(ps)):
		ps = rotate(ps)
		if not s.isprime(int(ps)):
			return False
	return True

c = 0
s = primes.testsieve()
for p in s.sieve():
	if p > 1000000:
		break
	if testrotate(p):
		c += 1

print "Found %d circular primes" % (c)