Catalan numbers/Pascal's triangle: Difference between revisions

Content added Content deleted
(rearranges in order of the language.)
(→‎{{header|Ruby}}: Rubyfy and simplify)
Line 741: Line 741:
<lang tcl>def catalan(num)
<lang tcl>def catalan(num)
t = [0, 1] #grows as needed
t = [0, 1] #grows as needed
1.upto(num).map do |i|
(1..num).map do |i|
i.downto(1){|j| t[j] += t[j-1]}
i.downto(1){|j| t[j] += t[j-1]}
t[i+1] = t[i]
t[i+1] = t[i]
Line 749: Line 749:
end
end


puts catalan(15).join(", ")</lang>
p catalan(15)</lang>
{{out}}
{{out}}
<pre>
<pre>1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845</pre>
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
</pre>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==