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?
A problem of 'combination'
From observation:
2 * grid_len
steps to finishgrid_len
steps to go down, so is to go right2 * grid_len
steps, if 'go down' steps is determined, other steps must be 'go right'So this problem is simplified to caculate how many ways to choose grid_len
steps (down / right) from 2 * grid_len
steps.
Solution is $$ C_{steps}^{grid\_len} $$
from math import factorial
def solve(grid_len):
steps = grid_len * 2
return factorial(steps) // (factorial(grid_len) * factorial(steps - grid_len))
solve(2)
solve(20)