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? Run this solution at repl.io here.
#So solution does not require code: it is simply 2n Choose n:
# 40 choose 20 = 137846528820
def factorial(n):
result = 1
for n in range(2,n+1):
result = result * n
return result
def countpath(n):
#counting over a square grid from corner to corner
combination = factorial(2*n) // (factorial(n) * factorial(n))
return(combination)
print(countpath(20))