def galton(m, n):
if m == 0:
if n == 0:
return 1
else:
return 0
else:
if n == 0:
return 1
else:
return (galton(m-1, n-1) + galton(m-1, n))
Hello, does anybody know how I can change this Code from recursive to iterative? I tried it with the Galton formula, but I only got the probability.
Code:
import operator as op
from functools import reduce
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer / denom *(0.5**n)