Jump to content

Catalan numbers: Difference between revisions

Added iterative solution
(Added zkl)
(Added iterative solution)
Line 2,894:
}
println("%2d --> %,d".fmt(100, catalan(100)));</lang>
And an iterative solution at works up to the limit of 64 bit ints (n=33). Would be 35 but need to avoid factional intermediate results.
<lang zkl>fcn catalan(n){ (1).reduce(n,fcn(p,n){ 2*(2*n-1)*p/(n+1) },1) }</lang>
{{out}}
<pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.