From Gray Cockroach, 8 Months ago, written in Text.
Embed
  1. def rWalk(n):
  2.     f = math.factorial
  3.     p1 = f(4*n)/f(2*n)/f(2*n)
  4.     p2 = f(2*n)/f(n)/f(n)
  5.     uu = pp = 0
  6.     for i in range(n+1):
  7.         mx = n-i
  8.         my = i
  9.         dx1 = n-mx
  10.         dy1 = n-i
  11.         dx2 = mx
  12.         dy2 = my
  13.         print f(dx1+dy1)/f(dx1)/f(dy1)*f(dx2+dy2)/f(dx2)/f(dy2)
  14.         pp += (f(dx1+dy1)/f(dx1)/f(dy1))**2
  15.         uu += f(dx1+dy1)/f(dx1)/f(dy1)
  16.     return round(100.*pp/uu**2,1)