Catalan numbers/Pascal's triangle: Difference between revisions
Content added Content deleted
(added Factor) |
(Scala solution added) |
||
Line 1,549: | Line 1,549: | ||
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
||
=={{header|Scala}}== |
|||
<lang Scala>def catalan(n: Int): Int = |
|||
if (n <= 1) 1 |
|||
else (0 until n).map(i => catalan(i) * catalan(n - i - 1)).sum |
|||
(1 to 15).map(catalan(_))</lang> |
|||
{{Out}}See it in running in your browser by [https://scastie.scala-lang.org/2ybpRZxCTOyrx3mIy8yIDw Scastie (JVM)]. |
|||
=={{header|Scilab}}== |
=={{header|Scilab}}== |
||
<lang>n=15 |
<lang>n=15 |