Catalan numbers/Pascal's triangle: Difference between revisions

m
→‎{{header|REXX}}: fixed handling of default args, changed/added comments and whitespace.
No edit summary
m (→‎{{header|REXX}}: fixed handling of default args, changed/added comments and whitespace.)
Line 1,174:
<lang rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N==".," then N=15 /*Not specified? Then use the default.*/
numeric digits max(9, N%2 + N%8) /*so we can handle huge Catalan numbers*/
@.=0; @.1=1 /*stem array default; define 1st value.*/
 
do i=1 for N; ip=i+1
do j=i by -1 for N; jm=j-1; @.j=@.j+@.jm; end /*j*/
@.ip=@.i; do k=ip by -1 for N; km=k-1; @.k=@.k+@.km; end /*k*/
@.ip=@.i
do k=ip by -1 for N; km=k-1; @.k=@.k+@.km; end /*k*/
say @.ip - @.i /*display the Ith Catalan number. */
end /*i*/ /*stick a fork in it, we're all done. */</lang>
Line 1,206 ⟶ 1,205:
<lang rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N==".," then N=15 /*Not specified? Then use the default.*/
numeric digits max(9, N%2 + N%8) /*so we can handle huge Catalan numbers*/
@.=0; @.1=1 /*stem array default; define 1st value.*/
end do /*i*/=1 for N; ip=i+1
 
do ij=i by -1 for N; ip@.j=i@.j+@(j-1); end /*j*/
@.ip=@.i; do jk=i ip by -1 for N; @.jk=@.jk+@(jk-1); end /*jk*/
say @.ip= - @.i; do k=ip by -1 /*display forthe N; @.k=@.k+@(k-1);Ith endCatalan number. /*k*/
say @.ip - @.i end /*display the Ith Catalan number. i*/
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,223 ⟶ 1,221:
<lang rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N==".," then N=15 /*Not specified? Then use the default.*/
numeric digits max(9, N%2 + N%8) /*so we can handle huge Catalan numbers*/
do j=1 for N /* [↓] display N Catalan numbers. */
 
do j=1 for N say comb(j+j, j) % (j+1) /*display [↓]the display NJth Catalan numbersnumber. */
say comb(j+j,j) % (j+1) end /*display the Jth Catalan number. j*/
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,241 ⟶ 1,238:
<lang rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N==".," then N=15 /*Not specified? Then use the default.*/
numeric digits max(9, N%2 + N%8) /*so we can handle huge Catalan numbers*/
!.=.
do j=1 for N do j=1 for N /* [↓] display N Catalan numbers. */
say comb(j+j,j) % (j+1) say comb(j+j, j) % (j+1) /*display the Jth Catalan number. */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/