Catalan numbers: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Sidef}}: updated code) |
||
Line 3,753: | Line 3,753: | ||
With memoization: |
With memoization: |
||
<lang ruby>func c(n) is cached { |
<lang ruby>func c(n) is cached { |
||
n == 0 ? 1 : (c(n-1) * (4 * n - 2) / (n + 1)) |
n == 0 ? 1 : (c(n-1) * (4 * n - 2) / (n + 1)) |
||
}</lang> |
}</lang> |
||
Calling the function: |
Calling the function: |
||
<lang ruby>15.times { |i| |
<lang ruby>15.times { |i| |
||
say "#{i |
say "#{i}\t#{c(i)}" |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
Line 3,778: | Line 3,778: | ||
14 2674440 |
14 2674440 |
||
</pre> |
</pre> |
||
=={{header|smart BASIC}}== |
=={{header|smart BASIC}}== |