Catalan numbers/Pascal's triangle: Difference between revisions
m
→{{header|Phix}}: bigatom -> mpfr
(→Python :: Composition of pure functions: docstring edit) |
m (→{{header|Phix}}: bigatom -> mpfr) |
||
Line 1,438:
-- 35 56
-- 126 (unused)</lang>
The following bigatom version is over ten times faster than the equivalent on [[Catalan_numbers#Phix|Catalan_numbers]]▼
=== gmp version ===
{{libheader|
<lang Phix>include builtins\
function catalanB(integer n) -- very very fast!
sequence catalan =
p =
mpz p1 = mpz_init(1)
if n=0 then return
for i=1 to n do
for j=1 to n-i+1 do
mpz_set(p[j]
end for
end for
Line 1,458 ⟶ 1,459:
end function
▲printf(1,"%d: %s (%3.2fs)\n",{100,sc100,time()-t0})
{{out}}
<pre>
100: 896519947090131496687170070074100632420837521538745909320
250: 465116795969233796497747947259667807407291160080922096111953326525143875193659257831340309862635877995262413955019878805418475969029457769094808256
</pre>
▲The
a quick comparison showing the latter getting exponentially worse (then again I memoised the slowest recursive version):
<pre>
800 2000 4000 8000
catalanB: 0.6s 3.5s 14.5s 64s
catalan2m: 0.7s 7.0s 64.9s 644s
</pre>
|