Multiplication tables: Difference between revisions

m
→‎{{header|REXX}}: changed some comments and whitespace.
m (→‎{{header|REXX}}: changed some comments and whitespace.)
Line 3,421:
parse arg high . /*obtain optional grid size from the CL*/
if high=='' | high=="," then high=12 /*Not specified? Then use the default.*/
bar = '│' ; dash = "─" /*(vertical) bar; horizontal bar (dash)*/
bj = '┴' ; tj = "┬" /*bottom and top junctions (or tees).*/
cj = '┼' cj = '┼' /*center junction (or cross). */
lj = '├' ; rj = "┤" /*left and right junctions (or tees).*/
tlc = '┌' ; trc = "┐" /* top left and right corners. */
blc = '└' ; brc = "┘" /*bottom " " " " */
/* [↑] define stuff to hold box glyphs*/
cell = cj || copies(dash,max(5,length(high) +1)) /*define the top of the cell. */
sep = copies(cell, high+1)rj /*construct the table separator. */
size = length(cell) - 1 /*width for the products in the table. */
box. = left('', size) /*initialize all the cells in the table*/
do j=0 to high call buildLine r /*buildstep athrough single linezero of the───► grid high. */
box.r.c _=right(r*cj, size) - 2)'x ' /*build athe single multiplication cell."label" (border) number. */
@box.0.j=translatecenter(@_, tj, cj) size) /* " " " tj (top label junction/tee)cell. */
box.0j.0=center('times'_, max(5, size) ) /* " " /*redefine boxleft label cell.0.0 with "times". */
end /*cj*/
box.0.0=center('times', max(5, size)) /*redefine box.0.0 with "times". */
do r=0 to high; do @ r=sep1 for high /*step through allrow lines; use a mod sep one ───► high. */
do c=r to high /*step through column row ───► high. */
box.r.c=right(r*c, size) /*build a single multiplication cell. */
end end /*c*/
end /*r*/ end /*r*/ /*only build the top right-half of grid*/
 
do jr=0 to high; @=sep; L=length(sep) /*step through all zero ───► high. lines; use a mod sep*/
_=right(j, size - 2)'x 'if r==0 then do; @=overlay(tlc, @ , 1) /*use a better tlc (top left /*build the "label" (bordercorner) number. */
box.0.j=center(_, size) @=overlay(trc, @ , L) /* " " " trc ( top label cell." right " ). */
box.j.0=center(_, max(5, size) ) /* " " @=translate(@, tj,cj) /* left" label cell." " tj (top junction/tee).*/
end /*j*/ end
else @=overlay(lj, @, 1) /* " " " lj (left junction/tee).*/
 
say @ /*display a [↑]single table definegrid stuffline. to hold box glyphs*/
box.0.0=center('times', max(5, size)) /*redefine box.0.0 with "times". */
if r==0 then call buildLine 00 /* " " " blank grid " */
 
do r=1 for high call buildLine r /*stepbuild througha rowsingle line of the grid. one ───► high. */
do c=r to high if r==0 then call buildLine 00 /*stepdisplay througha columnsingle blank grid line. row ───► high. */
end /*r*/
box.r.c=right(r*c, size) /*build a single multiplication cell. */
end /*c*/
end /*r*/ /*only build the top right-half of grid*/
 
do r=0 to high; @=sep /*step through all lines; use a mod sep*/
if r==0 then do
@=overlay(tlc, @ , 1) /*use a better tlc (top left corner). */
@=overlay(trc, @ , length(sep)) /* " " " trc ( " right " ). */
@=translate(@, tj, cj) /* " " " tj (top junction/tee).*/
end
else @=overlay(lj, @, 1) /* " " " lj (left junction/tee).*/
say @ /*display a single table grid line. */
if r==0 then call buildLine 00 /* " " " blank grid " */
call buildLine r /*build a single line of the grid. */
if r==0 then call buildLine 00 /*display a single blank grid line. */
end /*r*/
 
@=sep /*allow use of a modified separator. */
@=overlay(blc, @ , 1) /*use a better bottom left corner. */
Line 3,467 ⟶ 3,461:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
buildLine: parse arg row,,$; do col=0 to high /*start withstep athrough blank cellzero ───► ($)high. */
do col $=0$ ||bar to||box.row.col high/*build one cell at a time. /*step through zero ───► high. */
$=$ || barend || box.row.col /*buildcol*/ one cell at a time. /* [↑] build (row) line by cols*/
say $ || bar; return end /*colfinish building the last cell.*/</lang>
say $ || bar /*finish building the last cell.*/
return</lang>
'''output''' &nbsp; when using the default input:
<pre>