Calculates the n-th Catalan number, (2N)! / (N! * (N + 1)!), in a mathematical operations efficient way.
Ali Hamdi Ali Fadel · @AliOsm · about 3 years
Calculates the n-th Catalan number, (2N)! / (N! * (N + 1)!), in a mathematical operations efficient way.
def nth_catalan(n)result = 1m = n + 2while m <= 2 * n doresult = result * m / (m - n - 1)m += 1endresult /= (m - n - 1)end