Stirling numbers of the second kind: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments, expaciated the title for the "row".) |
|||
Line 1,130: | Line 1,130: | ||
numeric digits max(9, 2*lim) /*(over) specify maximum number in grid*/ |
numeric digits max(9, 2*lim) /*(over) specify maximum number in grid*/ |
||
@.= |
@.= |
||
do j=0 for lim+1 |
do j=0 for lim+1 |
||
@.j.j = 1; if j==0 then iterate |
@.j.j = 1; if j==0 then iterate /*define the right descending diagonal.*/ |
||
@.0.j = 0; @.j.0 = 0 |
@.0.j = 0; @.j.0 = 0 /* " " zero values. */ |
||
end /*j*/ |
end /*j*/ |
||
max#.= 0 /* [↓] calculate values for the grid. */ |
max#.= 0 /* [↓] calculate values for the grid. */ |
||
do n=0 for lim+1; np= n + 1 |
do n=0 for lim+1; np= n + 1 |
||
do k=1 for lim; km= k - 1 |
do k=1 for lim; km= k - 1 |
||
@.np.k = k * @.n.k + @.n.km |
@.np.k = k * @.n.k + @.n.km /*calculate a number in the grid. */ |
||
max#.k= max(max#.k, @.n.k) |
max#.k= max(max#.k, @.n.k) /*find the maximum value for a column. */ |
||
max#.b= max(max#.b, @.n.k) |
max#.b= max(max#.b, @.n.k) /*find the maximum value for all rows. */ |
||
end /*k*/ |
end /*k*/ |
||
end /*n*/ |
end /*n*/ |
||
/* [↓] only show the maximum value ? */ |
/* [↓] only show the maximum value ? */ |
||
do k=0 for lim+1 /*find max column width for each column*/ |
do k=0 for lim+1 /*find max column width for each column*/ |
||
Line 1,152: | Line 1,152: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
end |
end |
||
wgi= max(5, length(lim+1) ) /*the maximum width of the grid's index*/ |
|||
say ' |
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 c=0 for lim+1 until c>=r /*build a row of grid, 1 col at a time.*/ |
|||
$= $ right(@.r.c, length(max#.c) ) /*append a column to a row of the grid.*/ |
|||
end /*c*/ |
|||
say center(r, wgi) strip( substr($,2), 'T') /*display a single row of the grid. */ |
|||
end /*r*/ /*stick a fork in it, we're all done. */</lang> |
|||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
═row═ ══════════════════════════════columns══════════════════════════════ |
|||
0 1 |
0 1 |
||
1 0 1 |
1 0 1 |
||
2 0 1 1 |
2 0 1 1 |
||
3 0 1 3 1 |
3 0 1 3 1 |
||
4 0 1 7 6 1 |
4 0 1 7 6 1 |
||
5 0 1 15 25 10 1 |
5 0 1 15 25 10 1 |
||
6 0 1 31 90 65 15 1 |
6 0 1 31 90 65 15 1 |
||
7 0 1 63 301 350 140 21 1 |
7 0 1 63 301 350 140 21 1 |
||
8 0 1 127 966 1701 1050 266 28 1 |
8 0 1 127 966 1701 1050 266 28 1 |
||
9 0 1 255 3025 7770 6951 2646 462 36 1 |
9 0 1 255 3025 7770 6951 2646 462 36 1 |
||
10 0 1 511 9330 34105 42525 22827 5880 750 45 1 |
10 0 1 511 9330 34105 42525 22827 5880 750 45 1 |
||
11 0 1 1023 28501 145750 246730 179487 63987 11880 1155 55 1 |
11 0 1 1023 28501 145750 246730 179487 63987 11880 1155 55 1 |
||
12 0 1 2047 86526 611501 1379400 1323652 627396 159027 22275 1705 66 1 |
12 0 1 2047 86526 611501 1379400 1323652 627396 159027 22275 1705 66 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>}} |