Lah numbers: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) 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: | Line 231: | ||
=={{header|REXX}}== |
=={{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).*/ |
<lang rexx>/*REXX pgm computes & display (unsigned) Stirling numbers of the 3rd kind (Lah numbers).*/ |
||
parse arg lim . /*obtain optional argument from the CL.*/ |
parse arg lim . /*obtain optional argument from the CL.*/ |
||
Line 243: | Line 242: | ||
do n=0 to lim; nm= n - 1 |
do n=0 to lim; nm= n - 1 |
||
do k=0 to lim; km= k - 1 |
do k=0 to lim; km= k - 1 |
||
if k==1 then do; @.n.k= !(n); iterate; end |
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 then do; @.n.k= 1 ; iterate; end |
||
if k>n | k==0 | n==0 then do; @.n.k= 0 ; 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.*/ |
@.n.k = (!(n) * !(nm)) % (!(k) * !(km)) % !(n-k) /*calculate a # in the grid.*/ |
||
call maxer /*find max # " " " */ |
|||
max#.b= max(max#.b, @.n.k) /*find the maximum value for all rows. */ |
|||
end /*k*/ |
end /*k*/ |
||
end /*n*/ |
end /*n*/ |
||
Line 262: | Line 260: | ||
end /* [↑] the 100th row is when LIM is 99*/ |
end /* [↑] the 100th row is when LIM is 99*/ |
||
wi= max(3, length(lim+1) ) /*the maximum width of the grid's index*/ |
wi= max(3, length(lim+1) ) /*the maximum width of the grid's index*/ |
||
say 'row' center('columns', max#.a + lim, '═') /*display |
say 'row' center('columns', max(9, max#.a + lim), '═') /*display header of the grid.*/ |
||
do r=0 for lim+1; $= /* [↓] display the grid to the term. */ |
do r=0 for lim+1; $= /* [↓] display the grid to the term. */ |
||
Line 272: | Line 270: | ||
exit /*stick a fork in it, we're all done. */ |
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 ! |
!: parse arg z; if !.z\==. then return !.z; !=1; do f=2 to z; !=!*f; end; !.z=!; return ! |
||
maxer: max#.k= max(max#.k, @.n.k); max#.b= max(max#.b, @.n.k); return</lang> |
|||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
row ══════════════════════════════════════════════columns═══════════════════════════════════════════════ |
|||
row ══════════════════════════════════════════columns═══════════════════════════════════════════ |
|||
0 1 |
0 1 |
||
1 0 1 |
1 0 1 |
||
2 0 2 1 |
2 0 2 1 |
||
3 0 6 6 1 |
3 0 6 6 1 |
||
4 0 |
4 0 24 36 12 1 |
||
5 0 |
5 0 120 240 120 20 1 |
||
6 0 |
6 0 720 1800 1200 300 30 1 |
||
7 0 |
7 0 5040 15120 12600 4200 630 42 1 |
||
8 0 |
8 0 40320 141120 141120 58800 11760 1176 56 1 |
||
9 0 |
9 0 362880 1451520 1693440 846720 211680 28224 2016 72 1 |
||
10 0 |
10 0 3628800 16329600 21772800 12700800 3810240 635040 60480 3240 90 1 |
||
11 0 |
11 0 39916800 199584000 299376000 199584000 69854400 13970880 1663200 118800 4950 110 1 |
||
12 0 |
12 0 479001600 2634508800 4390848000 3293136000 1317254400 307359360 43908480 3920400 217800 7260 132 1 |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> -100 </tt>}} |
{{out|output|text= when using the input of: <tt> -100 </tt>}} |