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:
=={{header|REXX}}==
<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.*/
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
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 !
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:}}
<pre>
row ══════════════════════════════════════════════columns═══════════════════════════════════════════════
0 1
1 0 1
2 0 2 1
3 0 6 6 1
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
</pre>
{{out|output|text= when using the input of: <tt> -100 </tt>}}
|