Pascal's triangle: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, optimized the code (for speed), made the code simplier.
m (added whitespace before the TOC (Table Of Contents), added a Task (bold) header. split the task's requirement sentences into paragraphs, used a bigger font for the formula to make it easier to read the superscript, replace <= with ≤.)
m (→‎{{header|REXX}}: added/changed comments and whitespace, optimized the code (for speed), made the code simplier.)
Line 3,145:
if nn=='' | nn=="," then nn=10 /*Not specified? Then use the default.*/
N=abs(nn) /*N is the number of rows in triangle.*/
@.w=length( !(N-1; $.=@. ) / !(N%2) / !(N-1-N%2) ) /*defaultW: valuethe forwidth rowsof andthe forbiggest linesinteger.*/
w@.=length(!(N-1); / !(N%2) / !$.=@.; unity=right(N-1-N%2), w) /*W is the/*defaults widthrows of& thelines; biggestaligned numberunity.*/
/* [↓] build rows of Pascals' triangle*/
do r=1 for N; rm=r-1 /*Note: the first column is always 1.*/
Line 3,153:
$.r = $.r right(@.r.c, w) /*and construct a line for output (row)*/
end /*c*/ /* [↑] C is the column being built.*/
if r\==1 then $.r=$.r right(1,unity w) /*for most rowsrows≥2, append a trailing "1".*/
end /*r*/ /* [↑] R is the row being built.*/
/* [↑] WIDTH: for nicely looking line.*/
width=length($.N) /*width of the last (output) line (row)*/
/*if NN<0, output is written to a file.*/
do r=1 for N; $$=center($.r, width) /*show│writecenter linesthis (rows)particular ofPascals' trianglerow. */
if nn>0 then say center($.r, width) $$ /*SAY if NN is positive, else */
else call lineout 'PASCALS.'n, center($.r, width) $ /*write──►filewrite this Pascal's row ───► ifa notfile.*/
end /*r*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x; !=1; do j=2 to xarg(1); !=!*j; end /*j*/; return ! /*compute return !factorial*/</lang>
'''output''' &nbsp; when using the input of: &nbsp; <tt> 11 </tt>
<pre>