Vasu Balakrishnan’s Blog

Project Euler #13

leave a comment »


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

Answer: 5537376230


Thanks to this article, I got a good tip for reading file contents line by line, the Functional way. Since these were big numbers I used F# BigInt to solve the problem

var lContent = ReadLines("Problem13.txt")
                    .Select(pArg => BigInt.Parse(pArg));

var lAnswer = lContent.Aggregate(BigInt.Zero, 
                                (pSeed, pId) => pSeed + pId).ToString().Substring(0, 10);

Time: 25 ms


Written by nbvasu

May 15, 2009 at 3:14 pm

Posted in C#, Euler, General

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: