Catalan numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Ruby}}: use sum method)
m (→‎{{header|Lambdatalk}}: adding a vertical display)
Line 2,850: Line 2,850:
=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
{{trans|Javascript}}
{{trans|Javascript}}

<h3>1) catalan1</h3>

<syntaxhighlight lang="scheme">
<syntaxhighlight lang="scheme">
{def catalan1
{def catalan1
Line 2,857: Line 2,860:
-> catalan1
-> catalan1


{S.map catalan1 {S.serie 1 15}}
-> 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</syntaxhighlight>

<h3>2) catalan2</h3>

<syntaxhighlight lang="scheme">
{def catalan2
{def catalan2
{def catalan2.sum
{def catalan2.sum
Line 2,878: Line 2,888:
-> catalan2
-> catalan2


{S.map catalan2 {S.serie 0 15}}
-> 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845

</syntaxhighlight>

<h3>3) catalan3</h3>

<syntaxhighlight lang="scheme">
{def catalan3
{def catalan3
{def catalan3.loop
{def catalan3.loop
Line 2,896: Line 2,914:
-> catalan3
-> catalan3


1 {S.map catalan1 {S.serie 1 15}}
->
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
{S.map catalan2 {S.serie 0 15}}
->
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
{S.map catalan3 {S.serie 0 15}}
{S.map catalan3 {S.serie 0 15}}
-> 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
->
</syntaxhighlight>
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845

<h3>4) Alternative for a vertical diplay</h3>

<syntaxhighlight lang="scheme">

{style
td { text-align:right;
font-family:monospace;
}
}

{table
{tr {td} {td cat1} {td cat2} {td cat3}}
{S.map {lambda {:i} {tr {td :i}
{td {catalan1 :i}}
{td {catalan2 :i}}
{td {catalan3 :i}}}}
{S.serie 0 15}}
}

cat1 cat2 cat3
0 1 1 1
1 1 1 1
2 2 2 2
3 5 5 5
4 14 14 14
5 42 42 42
6 132 132 132
7 429 429 429
8 1430 1430 1430
9 4862 4862 4862
10 16796 16796 16796
11 58786 58786 58786
12 208012 208012 208012
13 742900 742900 742900
14 2674440 2674440 2674440
15 9694845 9694845 9694845

</syntaxhighlight>
</syntaxhighlight>