Created
October 23, 2015 20:43
-
-
Save deniskyashif/b33eb44f166f64662252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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