Lah numbers: Difference between revisions

m
→‎{{header|REXX}}: added code to guarantee enough width to show the header for the columns (for small grids), fixed the omission of finding the maximum column width where K=1.
m (→‎{{header|REXX}}: truncated column at k == 1)
m (→‎{{header|REXX}}: added code to guarantee enough width to show the header for the columns (for small grids), fixed the omission of finding the maximum column width where K=1.)
Line 231:
 
=={{header|REXX}}==
{{improve|REXX|The column where k equals 1 seems to have been truncated to a single digit}}
<lang rexx>/*REXX pgm computes & display (unsigned) Stirling numbers of the 3rd kind (Lah numbers).*/
parse arg lim . /*obtain optional argument from the CL.*/
Line 243 ⟶ 242:
do n=0 to lim; nm= n - 1
do k=0 to lim; km= k - 1
if k==1 then do; @.n.k= !(n); call maxer; iterate; end
if k==n then do; @.n.k= 1 ; iterate; end
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=call maxer 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*/
Line 262 ⟶ 260:
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', max(9, max#.a + lim), '═') /*display the header of the grid. */
 
do r=0 for lim+1; $= /* [↓] display the grid to the term. */
Line 272 ⟶ 270:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: parse arg z; if !.z\==. then return !.z; !=1; do f=2 to z; !=!*f; end; !.z=!; return !</lang>
maxer: max#.k= max(max#.k, @.n.k); max#.b= max(max#.b, @.n.k); return</lang>
{{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 4 24 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 0479001600 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>}}