-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15.py
19 lines (16 loc) · 1.1 KB
/
15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
############################################################################################################################################################
# Starting in the top left corner of a 2x2 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 20x20 grid? #
############################################################################################################################################################
def nop(point, grid_side, d):
if point in d:
return d[point]
if point[0] == grid_side or point[1] == grid_side:
d[point] = 1
return 1
val = nop((point[0] + 1, point[1]), grid_side, d) + nop((point[0], point[1] + 1), grid_side, d)
d[point] = val
return val
d = {}
print(nop((0, 0), 20, d))