rrdd rdrd rddr drrd drdr ddrr
Treating the paths as strings, we see that for an NxN grid, these are the permutations of N "d" and N "r" movements.
So there are (2N)! / (N!)^2.
For N = 20, (2N)! is huge; so we should simplify the expression first.
40! / (20! 20!) = ((403938...2221)20!) / (20! 20!)
In [1]:
n = 1
d = 1
for i in range(21,41):
n *= i
d *= (i - 20)
print n,d,n/d
In [ ]: