Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 2020 grid?
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:
Post a Comment