Project Euler
Problem 35: Circular Primes

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?



To begin with I used the Sieve of Eratosthenes to make an array of primes. I iterated through the primes and excluded any result that included a 0, 2, 4, 5, 6, or 8 in results greater than 10.

I made a function to rotate numbers and I made a function to test for circularity which used that function. The big speed breakthrough was in using a binary search to check if a number was in my array of primes.

82,999