RSS Feed Subscribe to RSS Feed


Project Euler, Problem 1 (in Groovy/Java)

I have been wanting to get up to speed with Groovy for while but hadn’t really found a good excuse. So when I came across Project Euler, I decided to try to solve the problems using Groovy.

I managed to solve Problem#1 today.

Note that I would describe the solutions below as being in Groovy/Java because I still fall back on my old Java habits rather than using all the Groovy language constructs available to me. Anyway…

The problem is:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

Unsurprisingly, I took the brute force approach first:

int n = 999, total=0;
for (int i in 1..n) {
    if ( (i%3==0) || (i%5==0) ) {
println("Total=" + total)

A good first start, but far from perfect as it loops through every number between 1 and n. I could improve it slightly by tweaking the start and end points (e.g. starting at 3), but it would still roughly involve n iterations.
My second attempt was this:

int n = 999, total=0;
Set nums = new HashSet();
for (int i=3; iProblem#2...

Tags: ,

Spec’ing and Pricing Client Projects

One of the toughest tasks on a project can be coming up with estimates, so I was interested to see this blog post quoting some of Joel Spolsky‘s thoughts on creating specifications and coming up with quotes for client work, which I think makes a lot of sense.


Back from Hiatus

It’s been a while since I have posted here; The last 2 months have been hectic. I started a new project at work (I’m “Tech Lead”, on site at a major bank here in California, using Java/XML/Spring), took a vacation in Europe, did a best man’s speech at a friends wedding, and completed the Escape From Alcatraz triathlon. Been a busy time!

I have a few ideas for upcoming articles, and I am also thinking about taking the Spring Certification exam. If so, I will be sure to post about it here…

Things Every Software Architect Should Know

There is an interesting article on TheServerSide today, about a book called “97 Things Every Software Architect Should Know”. It contains some good articles from some well known authors and architects, all short and easy to read. My personal favorites are