Anonymous user
Catalan numbers: Difference between revisions
m
→version 1: simplified a function, added whitespace to output section.
m (→version 1: indented a statement for alignment.) |
m (→version 1: simplified a function, added whitespace to output section.) |
||
Line 2,797:
@cat=' Catalan' /*a nice literal to have for the SAY. */
w=length(top) /*width of the largest number for SAY. */
call hdr 1A; do j=bot to top; say @cat right(j,w)": "
call hdr 1B; do j=bot to top; say @cat right(j,w)": "
call hdr 2 ; do j=bot to top; say @cat right(j,w)": "
call hdr 3 ; do j=bot to top; say @cat right(j,w)": "
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
comb: procedure; parse arg x,y; return pFact(x-y+1,x) % pFact(2,y)
pFact: procedure; !=1; do k=arg(1) to arg(2); !=!*k; end; return !
Line 2,815:
!.x=!; return !
/*──────────────────────────────────Catalan method 2──────────────────────────*/
do k=0 to n-1;
c.n=
/*──────────────────────────────────Catalan method 3──────────────────────────*/
if c.n==. then c.n=(4*n-2) * catalan3(n-1) % (n+1);
'''output''' when using the input of: <tt> 0 16 </tt>
<pre>
───────────────────────── Catalan numbers, method 1A ──────────────────────────
|