Vasu Balakrishnan’s Blog

Project Euler #20

leave a comment »

Problem: Find the sum of digits in 100!

Answer: 648

Solution: Thanks to Microsoft.FSharp.Math.BigInt, computing the factorial of a number in built in.

var lOutput = BigInt.Factorial(new BigInt(100));
var lAnswer = lOutput.ToDigits().Sum();

// Extensions

public static IEnumerable<int> ToDigits(this BigInt pBigInt)
    return pBigInt.ToString().Select(pChar => (pChar - 48));

Time: 213 ms


Written by nbvasu

May 15, 2009 at 1:56 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: