Project Euler Problem #13

January 27, 2010

Read the details of the problem here


Find the first ten digits of the sum of one-hundred 50-digit numbers.


It’s a no-brainer.

def nums = [
53503534226472524250874054075591789781264330331690 ]

def answer = nums.sum().toString()[0..9]

I only need to really sum the first 11-digits of each number, so longs would have sufficed but this was so tempting I just did the simplest thing.

This runs in 0.43 seconds. Slow, but I’m not going to worry about this for a problem of this sort.


Groovy made this a snap with automatic BigInteger casting and a suitable aggregation listop.


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: