Friday 10 April 2009

PROJECT EULER #15

Link to page

Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 20×20 grid?

I used this file to generate BigInt

using System;

namespace ProjectEuler
{
class Program
{
static void Main()
{
//Problem 15
DateTime start = DateTime.Now;
//This is a staircase walk problem
//For a (m x n) grid the answer is
//(m + n)! / m!n! = 40!/(20!*20!)
BigInt answer = Factorial(40)/(Factorial(20)*Factorial(20));
Console.WriteLine(answer);
TimeSpan time = DateTime.Now-start;
Console.WriteLine("This took {0}", time);
Console.ReadKey();
}
public static BigInt Factorial(BigInt n)
{
return ((n == 0) ? 1 : n*Factorial(n - 1));
}
}
}

No comments: