How to resolve the algorithm Stirling numbers of the second kind step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Stirling numbers of the second kind step by step in the Raku programming language
Table of Contents
Problem Statement
Stirling numbers of the second kind, or Stirling partition numbers, are the number of ways to partition a set of n objects into k non-empty subsets. They are closely related to Bell numbers, and may be derived from them.
Stirling numbers of the second kind obey the recurrence relation:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Stirling numbers of the second kind step by step in the Raku programming language
Source code in the raku programming language
sub Stirling2 (Int \n, Int \k) {
((1,), { (0, |@^last) »+« (|(@^last »*« @^last.keys), 0) } … *)[n;k]
}
my $upto = 12;
my $mx = (1..^$upto).map( { Stirling2($upto, $_) } ).max.chars;
put 'Stirling numbers of the second kind: S2(n, k):';
put 'n\k', (0..$upto)».fmt: "%{$mx}d";
for 0..$upto -> $row {
$row.fmt('%-3d').print;
put (0..$row).map( { Stirling2($row, $_) } )».fmt: "%{$mx}d";
}
say "\nMaximum value from the S2(100, *) row:";
say (^100).map( { Stirling2 100, $_ } ).max;
You may also check:How to resolve the algorithm Middle three digits step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Polymorphic copy step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Add a variable to a class instance at runtime step by step in the Pop11 programming language
You may also check:How to resolve the algorithm Nim game step by step in the Arturo programming language
You may also check:How to resolve the algorithm Pig the dice game/Player step by step in the C++ programming language