Skip to content

Instantly share code, notes, and snippets.

@deniskyashif
Created October 23, 2015 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deniskyashif/b33eb44f166f64662252 to your computer and use it in GitHub Desktop.
Save deniskyashif/b33eb44f166f64662252 to your computer and use it in GitHub Desktop.
/*
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20×20 grid?
*/
using System;
class Program
{
static void Main()
{
var size = 20;
var grid = new long[size + 1, size + 1];
for (int i = 0; i < size + 1; i++)
{
grid[i, 0] = 1;
grid[0, i] = 1;
}
for (int i = 1; i < grid.GetLength(0); i++)
for (int k = 1; k < grid.GetLength(1); k++)
grid[i, k] = grid[i, k - 1] + grid[i - 1, k];
Console.WriteLine(grid[grid.GetLength(0) - 1, grid.GetLength(1) - 1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment