Catalan numbers: Difference between revisions
Content added Content deleted
Line 4,563: | Line 4,563: | ||
9694845 |
9694845 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ |
|||
'''IFERR''' R→B '''THEN END''' |
|||
'''IF''' DUP #1 ≠ |
|||
'''THEN''' |
|||
DUP 2 * 1 - 2 * OVER 1 - →CAT * SWAP 1 + / |
|||
'''END''' |
|||
≫ ''''→CAT'''' STO |
|||
| |
|||
''( n -- C(n) )'' |
|||
Ignore the conversion error if n is already a binary integer |
|||
C(1) = 1 |
|||
Divide by (n+1) at the end to stay in the integer world |
|||
|} |
|||
To speed up execution, additions can be preferred to multiplications by replacing <code>2 *</code> with <code>DUP +</code>. |
|||
The following piece of code will deliver what is required: |
|||
≪ 1 { } '''DO''' OVER →CAT B→R + SWAP 1 + SWAP '''UNTIL''' OVER 15 > '''END''' ≫ EVAL |
|||
{{out}} |
|||
<pre> |
|||
1: { 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 } |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{libheader|RubyGems}} |
{{libheader|RubyGems}} |
||
Line 4,630: | Line 4,661: | ||
15 : 9694845 9694845 9694845 |
15 : 9694845 9694845 9694845 |
||
</pre> |
</pre> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
<syntaxhighlight lang="runbasic">FOR i = 1 TO 15 |
<syntaxhighlight lang="runbasic">FOR i = 1 TO 15 |