Multiplication tables: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed some comments and whitespace.) |
|||
Line 3,421: | Line 3,421: | ||
parse arg high . /*obtain optional grid size from the CL*/ |
parse arg high . /*obtain optional grid size from the CL*/ |
||
if high=='' | high=="," then high=12 /*Not specified? Then use the default.*/ |
if high=='' | high=="," then high=12 /*Not specified? Then use the default.*/ |
||
bar = '│' |
bar = '│' ; dash = "─" /*(vertical) bar; horizontal bar (dash)*/ |
||
bj = '┴' |
bj = '┴' ; tj = "┬" /*bottom and top junctions (or tees).*/ |
||
cj = '┼' /*center junction (or cross). */ |
|||
lj = '├' |
lj = '├' ; rj = "┤" /*left and right junctions (or tees).*/ |
||
tlc = '┌' |
tlc = '┌' ; trc = "┐" /* top left and right corners. */ |
||
blc = '└' |
blc = '└' ; brc = "┘" /*bottom " " " " */ |
||
⚫ | |||
cell = cj || copies(dash,max(5,length(high) +1)) /*define the top of the cell. */ |
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. */ |
sep = copies(cell, high+1)rj /*construct the table separator. */ |
||
size = length(cell) - 1 /*width for the products in the table. */ |
size = length(cell) - 1 /*width for the products in the table. */ |
||
box. = left('', size) /*initialize all the cells in the table*/ |
box. = left('', size) /*initialize all the cells in the table*/ |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
box.0.0=center('times', max(5, size)) /*redefine box.0.0 with "times". */ |
|||
⚫ | |||
do c=r to high /*step through column row ───► high. */ |
|||
box.r.c=right(r*c, size) /*build a single multiplication cell. */ |
|||
⚫ | |||
⚫ | |||
do |
do r=0 to high; @=sep; L=length(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, @ , L) /* " " " trc ( " right " ). */ |
|||
@=translate(@, tj,cj) /* " " " tj (top junction/tee).*/ |
|||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
call buildLine r /*build a single line of the grid. */ |
|||
if r==0 then call buildLine 00 /*display a single blank grid line. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if r==0 then do |
|||
@=overlay(tlc, @ , 1) /*use a better tlc (top left corner). */ |
|||
@=overlay(trc, @ , length(sep)) /* " " " trc ( " right " ). */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
say @ /*display a single table grid line. */ |
|||
⚫ | |||
⚫ | |||
if r==0 then call buildLine 00 /*display a single blank grid line. */ |
|||
⚫ | |||
@=sep /*allow use of a modified separator. */ |
@=sep /*allow use of a modified separator. */ |
||
@=overlay(blc, @ , 1) /*use a better bottom left corner. */ |
@=overlay(blc, @ , 1) /*use a better bottom left corner. */ |
||
Line 3,467: | Line 3,461: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
buildLine: parse arg row,,$ |
buildLine: parse arg row,,$; do col=0 to high /*step through zero ───► high. */ |
||
$=$ ||bar ||box.row.col /*build one cell at a time. */ |
|||
end /*col*/ /* [↑] build (row) line by cols*/ |
|||
say $ || bar; return /*finish building the last cell.*/</lang> |
|||
say $ || bar /*finish building the last cell.*/ |
|||
return</lang> |
|||
'''output''' when using the default input: |
'''output''' when using the default input: |
||
<pre> |
<pre> |