Project Euler 13

This one was a bit confusing.  The wording of the problem is, “Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.”  I assumed that they wanted the ones place through the billionths place, but they wanted the first ten digits starting from the left side of the number.

The reason this isn’t super-easy, is that most (all?) programming languages can’t handle large numbers.  Javascript, for instance, cannot do numbers larger than 2^53, or 9007199254740992 (ECMA.  See also this good discussion).  That being said, I was able to add these numbers together using javascript and I was able to see the first 15 or so numbers.  Kind of a boring problem, but maybe I’m missing something.

EDIT: After reading the forums on projecteuler, there are several different ways of solving this problem.  My solution made use of an array, but to check myself I simply added the numbers together and got the same answer both ways.  Some solutions used the data type double (decimals), some only added part of each number, etc.  This problem seems like a great way to see how a person finds an algorithm that isn’t immediately obvious, when there are several options.


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 )

Facebook photo

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

Connecting to %s