Catalan numbers: Difference between revisions
Content deleted Content added
m →version 1: simplified a function, added whitespace to output section. |
m added bigatom handling |
||
Line 2,376:
-- An explicitly memoized version of what seems to be the best, and the one that really needed it:
--
-- I also converted this to use bigatoms.
include builtins\bigatom.e
sequence c2cache = {}
function
object r
if n
end if▼
for i=0 to n-1 do▼
c2cache[n] = r▼
end if
r = BA_ZERO
r = ba_add(r,ba_multiply(catalan2bc(i),catalan2bc(n-1-i)))
return r
end function
atom t0 = time() -- (this last call only)
string sc100 = ba_sprint(catalan2bc(100))
printf(1,"100: %s (%3.2fs)\n",{sc100,time()-t0})</lang>
{{out}}
<pre>
Line 2,414 ⟶ 2,421:
14: 2674440 2674440 2674440
15: 9694845 9694845 9694845
100: 896519947090131496687170070074100632420837521538745909320 (0.42s)
</pre>
|