Catalan numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Factor}}: no longer relevant)
(→‎{{header|Factor}}: add the binomial coefficient method)
Line 1,761: Line 1,761:


=={{header|Factor}}==
=={{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 method, memoized by using arrays.
<lang factor>USING: kernel math prettyprint sequences ;
<lang factor>USING: kernel math prettyprint sequences ;