How to resolve the algorithm Stirling numbers of the first kind step by step in the Raku programming language
How to resolve the algorithm Stirling numbers of the first kind step by step in the Raku programming language
Table of Contents
Problem Statement
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coefficients of polynomial expansions of falling or rising factorials. Depending on the application, Stirling numbers of the first kind may be "signed" or "unsigned". Signed Stirling numbers of the first kind arise when the polynomial expansion is expressed in terms of falling factorials; unsigned when expressed in terms of rising factorials. The only substantial difference is that, for signed Stirling numbers of the first kind, values of S1(n, k) are negative when n + k is odd. Stirling numbers of the first kind follow the simple identities:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Stirling numbers of the first kind step by step in the Raku programming language
Source code in the raku programming language
sub Stirling1 (Int \n, Int \k) {
return 1 unless n || k;
return 0 unless n && k;
state %seen;
(%seen{"{n - 1}|{k - 1}"} //= Stirling1(n - 1, k - 1)) +
(n - 1) * (%seen{"{n - 1}|{k}"} //= Stirling1(n - 1, k))
}
my $upto = 12;
my $mx = (1..^$upto).map( { Stirling1($upto, $_) } ).max.chars;
put 'Unsigned Stirling numbers of the first kind: S1(n, k):';
put 'n\k', (0..$upto)».fmt: "%{$mx}d";
for 0..$upto -> $row {
$row.fmt('%-3d').print;
put (0..$row).map( { Stirling1($row, $_) } )».fmt: "%{$mx}d";
}
say "\nMaximum value from the S1(100, *) row:";
say (^100).map( { Stirling1 100, $_ } ).max;
You may also check:How to resolve the algorithm Calkin-Wilf sequence step by step in the 11l programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the Scheme programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the Lua programming language
You may also check:How to resolve the algorithm Search a list of records step by step in the C# programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element insertion step by step in the Axe programming language