Created
January 11, 2014 02:14
-
-
Save kaipakartik/8366140 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?
This file contains hidden or 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
short = dict() | |
def getPaths(x, y): | |
if x == 0 and y == 0: | |
return 0 | |
if x == 0: | |
return 1 | |
if y == 0: | |
return 1 | |
if (x,y) in short: | |
return short[x,y] | |
# print x, y | |
short[x,y] =getPaths(x, y - 1) + getPaths(x-1, y) | |
return short[x,y] | |
print getPaths(20, 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment