Anonymous user
Catalan numbers: Difference between revisions
→{{header|Julia}}
(→{{header|Scala}}: fixed) |
|||
Line 2,117:
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang julia>Catalan(n::Integer) = div(binomial(2n, n), n+1)</lang>▼
@show catalannum.(1:15)
@show catalannum(big(100))</lang>
{{out}}
<pre>catalannum.(1:15) = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
catalannum(big(100)) = 896519947090131496687170070074100632420837521538745909320</pre>▼
▲896519947090131496687170070074100632420837521538745909320
(In the second example, we have used arbitrary-precision integers to avoid overflow for large Catalan numbers.)
|