Stirling numbers of the first kind: Difference between revisions

(Added Lua)
 
(3 intermediate revisions by 2 users not shown)
Line 115:
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses the Algol 68G LONG LONG INT mode which provides large-precision integers. As the default number of digits is insufficient for the task, the maximum nunber of digits is specified by a pragmatic comment.
<syntaxhighlight lang="algol68">BEGIN
BEGIN # show some (unsigned) Stirling numbers of the first kind #
 
# specify the precision of LONG LONG INT, we need about 160 digits #
Line 145:
REF[,]SINT s1 = make s1( max stirling, FALSE );
print( ( "Unsigned Stirling numbers of the first kind:", newline ) );
print( ( " k 0" ) );
FOR k FROM 0 TO max stirling DO print( ( whole( k, IF k < 6 THEN -10 ELSE -9 FI ) ) ) OD;
print( ( newline, " n", newline ) );
FOR n FROM 0 TO max stirling DO
print( ( whole( n, -2 ), whole( s1[ n, 0 ], -3 ) ) );
FOR k FROM 0 TO n DO
print( ( whole( s1[ n, k ], IF k < 6 THEN -10 ELSE -9 FI ) ) )
OD;
print( ( newline ) )
Line 167:
print( ( whole( max 100, 0 ), newline ) )
END
END
END</syntaxhighlight>
{{out}}
<pre>
Unsigned Stirling numbers of the first kind:
k 0 1 2 3 4 5 6 7 8 9 10 11 12
n
0 1
1 0 1
2 0 1 1
3 0 2 3 1
4 0 6 11 6 1
5 0 24 50 35 10 1
6 0 120 274 225 85 15 1
7 0 720 1764 1624 735 175 21 1
8 0 5040 13068 13132 6769 1960 322 28 1
9 0 40320 109584 118124 67284 22449 4536 546 36 1
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
Maximum Stirling number of the first kind with n = 100:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
Line 191 ⟶ 192:
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">begin % show some (unsigned) Stirling numbers of the first kind %
begin % show some (unsigned) Stirling numbers of the first kind %
integer MAX_STIRLING;
MAX_STIRLING := 12;
Line 211 ⟶ 213:
% print the Stirling numbers up to n, k = 12 %
write( "Unsigned Stirling numbers of the first kind:" );
write( " k 0" );
for k := 01 until MAX_STIRLING do writeon( i_w := if k < 6 then 10 else 9, s_w := 0, k );
write( " n" );
for n := 0 until MAX_STIRLING do begin
write( i_w := 2, s_w := 0, n, i_w := 3, s1( n, 0 ) );
for k := 01 until n do begin
writeon( i_w := if k < 6 then 10 else 9, s_w := 0, s1( n, k ) )
end for_k
end for_n
end
end.
end.</syntaxhighlight>
{{out}}
<pre>
Unsigned Stirling numbers of the first kind:
k 0 1 2 3 4 5 6 7 8 9 10 11 12
n
0 1
1 0 1
2 0 1 1
3 0 2 3 1
4 0 6 11 6 1
5 0 24 50 35 10 1
6 0 120 274 225 85 15 1
7 0 720 1764 1624 735 175 21 1
8 0 5040 13068 13132 6769 1960 322 28 1
9 0 40320 109584 118124 67284 22449 4536 546 36 1
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
</pre>
 
Line 1,754 ⟶ 1,757:
The maximum value (which has 158 decimal digits):
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
</pre>
 
=={{header|RPL}}==
« '''IF''' DUP2 AND NOT '''THEN''' ==
'''ELSE'''
SWAP 1 - DUP ROT
DUP2 1 - <span style="color:blue">US1</span> 4 ROLLD <span style="color:blue">US1</span> * +
'''END'''
» '<span style="color:blue">US1</span>' STO <span style="color:grey">''@ ( n k → unsigned S1(n,k) )''</span>
« { 12 12 } 0 CON
1 12 '''FOR''' n
1 n '''FOR''' k
n k 2 →LIST DUP EVAL <span style="color:blue">US1</span> PUT
'''NEXT NEXT'''
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: [[ 1 0 0 0 0 0 0 0 0 0 0 0 ]
[ 1 1 0 0 0 0 0 0 0 0 0 0 ]
[ 2 3 1 0 0 0 0 0 0 0 0 0 ]
[ 6 11 6 1 0 0 0 0 0 0 0 0 ]
[ 24 50 35 10 1 0 0 0 0 0 0 0 ]
[ 120 274 225 85 15 1 0 0 0 0 0 0 ]
[ 720 1764 1624 735 175 21 1 0 0 0 0 0 ]
[ 5040 13068 13132 6769 1960 322 28 1 0 0 0 0 ]
[ 40320 109584 118124 67284 22449 4536 546 36 1 0 0 0 ]
[ 362880 1026576 1172700 723680 269325 63273 9450 870 45 1 0 0 ]
[ 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1 0 ]
[ 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1 ]]
</pre>
 
1,151

edits