Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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?
- n = 20
- array = []
- for i in range(n+1):
- array.append([])
- #only one way to get to each of these points(first row), so we mark each of those with a 1
- for x in range(0,n+1):
- array[0].append(1)
- #only one way to get to each of these points(first col), so we mark each of those with a 1
- for y in range(1,n+1):
- array[y].append(1)
- #starting at element element (1,1) we add above element mark and left element mark.
- for x in range(1,n+1):
- for y in range(1,n+1):
- array[x].append(array[x][y-1]+array[x-1][y])
- print array[20][20]
Advertisement
Add Comment
Please, Sign In to add comment