Project Euler – A Groovy Approach

October 9, 2009

I recently came across Project Euler which is a site that hosts a “series of challenging mathematical/computer programming problems” in order to “provide a platform for the inquiring mind to…learn new concepts in a fun and recreational context.”

Having some time on my hands recently I decided that I’d like to have a go at some of the problems and thought that I’d take the opportunity to use Groovy, which I’m learning, to do any necessary programming in.

I’m going to write up my solutions here, in brief, to the problems I tackle and comment on how Groovy was, or wasn’t, of help in the development. I’ll just be using the Java 6 Runtime & Groovy 1.6 SDK without adding on 3rd party libraries that might take some of the headache away. I am trying to pick things up from first principles as much as possible.

I don’t think I’ll be giving anything away – Project Euler has been around for quite a while, since October 2001, and the answers to the older, easier questions are already available on the Internet. I expect it’ll take me quite a while to get to the point where a solution isn’t published somewhere.

The Project Euler website recommends that programmatic solutions should run in under 60 seconds. Since that was around written around 8 years ago and given the increase in computer power over that time, I’ll be aiming for my solutions to run in under 15 seconds (even if I need to slip into proper compiled Java code from time-to-time).

I’m developing on an Acer Aspire 8930G w/ 2.53 GHz Core 2 Duo CPU and 4GB RAM running Windows Vista Ultimate SP2 32-bit. It gets 5.4 and 5.9 Windows Performance Ratings for the Processor and Memory respectively.

Note: Some of the programming I’ll be doing might be a bit slip-shod and not up to "enterprise” standards – this is a hobby project after all! I’ll make appropriate notes on such as I progress.

Update: March 2012

I’m now developing on a Samsung 700G7A-S02UK. This has an Intel Core i7-2670QM (quad core 2.20-3.1 GHz) CPU and 8 GB RAM running Windows 7 Home Premium SP1 64-bit. It gets 7.5 and 7.6 Windows Performance Ratings for the Processor and Memory respectively. I’m using Oracle Java 7u3 32-bit and Groovy 1.8.6 (last time I looked!).

After doing some comparative performance testing on an idle machine with around 50 of the previous Project Euler solution I found it runs around 3x-5x faster than the Acer 8930g. In one or two cases it was a fairly incredible 12x faster, but in another couple it was actually marginally slower. Interesting!

As a result of this upgrade, my target time for the Project Euler solutions is now down to 5 seconds (from 15s) and I’m going to take a close look at anything that takes more than 3 seconds.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: