Project Euler - Problem 006
Problem 6 is really easy to solve without needing any new extension methods nor complicated LINQ.
private static BigInteger GetAnswerToProblem6()
{
// Get the range of numbers to process for the problem.
IEnumerable<BigInteger> range = BigInteger.One.To(100);
// Determine the square of the sum of the values within the problem space.
BigInteger squareOfSum = BigInteger.Pow(range.Sum(), 2);
// Determine the sum of the squares of the values within the problem space.
BigInteger sumOfSquares = range.Select(bi => BigInteger.Pow(bi, 2)).Sum();
// Return the different.
return squareOfSum - sumOfSquares;
}
Tags
Revisions
-
9/19/2012 - Article published.