Project Euler
Posted by Christopher Pitzer on February 6th, 2008If you’re into puzzles and enjoy some light coding, you should check out Project Euler. It’s a site devoted to problems (mostly mathematical) which require a computer to be solved.
Problem 35
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?
Sure, you could solve that kind of problem on paper, but it would take you a lifetime. On the other hand, it is pretty simple if you attack it with a computer.
- Find all the prime numbers under a million.
- Split each number into a string and recombine it using all possible rotations.
- Test each rotation, if all are prime, add 1 to the tally.
When you have the answer, you can go back to ProjectEuler.net and punch it in. The site will keep track of which problems you’ve solved, and if you have lots of time on your hands, you might even make it on to a list of the top 1000 problem solvers.
If you like mulling over a problem in the back of your mind all day, Project Euler is worth a look.
Have fun, and let me know what you think!
Recent Comments