Jump to content

Catalan numbers: Difference between revisions

Line 2,117:
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang julia>Catalan(n::Integer) = div(binomial(2n, n), n+1)</lang>
 
<lang julia>Catalancatalannum(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]
<pre>julia> [Catalan(n) for n=1:15]
catalannum(big(100)) = 896519947090131496687170070074100632420837521538745909320</pre>
15-element Array{Int64,1}:
1
2
5
14
42
132
429
1430
4862
16796
58786
208012
742900
2674440
9694845
 
julia> Catalan(big(100))
896519947090131496687170070074100632420837521538745909320
</pre>
(In the second example, we have used arbitrary-precision integers to avoid overflow for large Catalan numbers.)
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.