Friday, May 6, 2011

Euler Project

Problem 19: How many Sundays fell on the first of the month during the twentieth century?
Problem 24: The lexicographic permutations of 0, 1 and 2 are:
012 021 102 120 201 210

What is the millionth lexicographic permutation of the digits 0,1,2,3,4,5,6,7,8 and 9?
Problem 60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property. 
Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.
Just some examples of questions posed by Project Euler, a list of 373 mathematical programming exercises (and counting).

Some are quite challenging, some are rather easy. But with the easier ones it's often still fun to find a solution that's nice and efficient. And a 'good' solution should give the answer in less than a minute. The number of Sundays in the 20th century, from the example above, happens to be *very* simple to approximate accurately, by just taking 1/7th of the total number of days.

I challenged myself to solve them all in one month. So far I've been working in Python, but maybe I can use this as an excuse to learn some new languages. Current status: 22 down, 314 to go!

Update November 2011: Well, one month was just a little overoptimistic. But I've made slow but steady progress, having currently solved nearly a hundred problems. They do get a lot more difficult than the examples I gave though.