Jump to content

Catalan numbers: Difference between revisions

→‎{{header|Factor}}: add the binomial coefficient method
m (→‎{{header|Factor}}: no longer relevant)
(→‎{{header|Factor}}: add the binomial coefficient method)
Line 1,761:
 
=={{header|Factor}}==
The first method:
This is the last solution, memoized by using arrays.
<lang factor>USING: kernel math math.combinatorics prettyprint ;
 
: catalan ( n -- n ) [ 1 + recip ] [ 2 * ] [ nCk * ] tri ;
 
15 [ catalan . ] each-integer</lang>
{{out}}
<pre>
1
1
2
5
14
42
132
429
1430
4862
16796
58786
208012
742900
2674440
</pre>
 
This is the last solutionmethod, memoized by using arrays.
<lang factor>USING: kernel math prettyprint sequences ;
 
1,827

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.