# HG changeset patch # User Dominic Cleal # Date 1228137293 0 # Node ID 836a4ccbcbae34b2dbfff403a26db0cd7430e514 # Parent 76155198a9e28c7bb18df6700a988584a7d83ea6 #35 solution diff -r 76155198a9e2 -r 836a4ccbcbae problem35.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/problem35.py Mon Dec 01 13:14:53 2008 +0000 @@ -0,0 +1,23 @@ +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) +