Catalan numbers/Pascal's triangle: Difference between revisions

→‎{{header|Perl}}: Add notes about overflow, and use a module
(add picolisp)
(→‎{{header|Perl}}: Add notes about overflow, and use a module)
Line 242:
{{out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
 
After the 28th Catalan number, this overflows 64-bit integers. We could add <tt>use bigint;</tt> <tt>use Math::GMP ":constant";</tt> to make it work, albeit not at a fast pace. However we can use a module to do it much faster:
{{libheader|ntheory}}
<lang Perl>use ntheory qw/binomial/;
print join(" ", map { binomial( 2*$_, $_) / ($_+1) } 1 .. 1000), "\n";</lang>
 
The <tt>Math::Pari</tt> module also has a binomial, but isn't as fast and overflows its stack after 3400.
 
=={{header|Perl 6}}==
Anonymous user