Lah numbers: Difference between revisions

→‎{{header|REXX}}: changed REXX program to use the maximum width for each column to minimize screen acreage.
m (Add missing parenthesis)
(→‎{{header|REXX}}: changed REXX program to use the maximum width for each column to minimize screen acreage.)
Line 149:
lim= abs(lim) /*only use the absolute value of LIM. */
numeric digits max(9, 4*lim) /*(over) specify maximum number in grid*/
max#.= 0
!.=.
@.= /* [↓] calculate values for the grid. */
Line 158:
if k>n | k==0 | n==0 then do; @.n.k= 0 ; iterate; end
@.n.k = (!(n) * !(nm)) % (!(k) * !(km)) % !(n-k) /*calculate a # in the grid.*/
max#.k= max(max#.k, @.n.k) /*find max # " " " */
max#.b= max(max#.b, @.n.k) /*find the maximum value for all rows. */
end /*k*/
end /*n*/
 
do k=0 for lim+1 /*find max column width for each column*/
max#.a= max#.a + length(max#.k)
end /*k*/
/* [↓] only show the maximum value ? */
w= length(max#.b) /*calculate max width of all numbers. */
if olim<0 then do; say 'The maximum value (which has ' w " decimal digits):"
say max# .b /*display maximum number in the grid. */
exit /*stick a fork in it, we're all done. */
end /* [↑] the 100th row is when LIM is 99*/
wi= max(3, length(lim+1) ) /*the maximum width of the grid's index*/
say 'row' center('columns', (wmax#.a +1)*( lim+1), '═') /*display the header of the grid. */
 
do r=0 for lim+1; $= /* [↓] display the grid to the term. */
do c=0 for lim+1 until c>=r /*build a row of grid, 1 col at a time.*/
$= $ right(@.r.c, wlength(max#.c) ) /*append a column to a row of the grid.*/
end /*c*/
say right(r,wi) strip(substr($,2), 'T') /*display a single row of the grid. */
Line 181 ⟶ 186:
{{out|output|text=&nbsp; when using the default input:}}
<pre>
row ══════════════════════════════════════════columns═══════════════════════════════════════════
row ════════════════════════════════════════════════════════════════════columns════════════════════════════════════════════════════════════════════
0 1
1 0 1
2 0 2 1
3 0 6 6 1
4 0 244 36 12 1
5 0 0 120 240 120 20 1
6 0 0 720 1800 1200 300 30 1
7 0 0 5040 15120 12600 4200 630 42 1
8 0 0 40320 141120 141120 58800 11760 1176 56 1
9 0 0 362880 1451520 1693440 846720 211680 28224 2016 72 1
10 0 0 3628800 16329600 21772800 12700800 3810240 635040 60480 3240 90 1
11 0 0 39916800 199584000 299376000 199584000 69854400 13970880 1663200 118800 4950 110 1
12 0 0 479001600 2634508800 4390848000 3293136000 1317254400 307359360 43908480 3920400 217800 7260 132 1
</pre>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> -100 </tt>}}