How to resolve the algorithm Stirling numbers of the first kind step by step in the Sidef programming language
How to resolve the algorithm Stirling numbers of the first kind step by step in the Sidef 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 Sidef programming language
Source code in the sidef programming language
func S1(n, k) { # unsigned Stirling numbers of the first kind
stirling(n, k).abs
}
const r = (0..12)
var triangle = r.map {|n| 0..n -> map {|k| S1(n, k) } }
var widths = r.map {|n| r.map {|k| (triangle[k][n] \\ 0).len }.max }
say ('n\k ', r.map {|n| "%*s" % (widths[n], n) }.join(' '))
r.each {|n|
var str = ('%-3s ' % n)
str += triangle[n].map_kv {|k,v| "%*s" % (widths[k], v) }.join(' ')
say str
}
with (100) {|n|
say "\nMaximum value from the S1(#{n}, *) row:"
say { S1(n, _) }.map(^n).max
}
func S1((0), (0)) { 1 }
func S1(_, (0)) { 0 }
func S1((0), _) { 0 }
func S1(n, k) is cached { S1(n-1, k-1) + (n-1)*S1(n-1, k) }
You may also check:How to resolve the algorithm Animation step by step in the Rust programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Genyris programming language
You may also check:How to resolve the algorithm Multisplit step by step in the Raku programming language
You may also check:How to resolve the algorithm Josephus problem step by step in the Objeck programming language
You may also check:How to resolve the algorithm Fork step by step in the Ada programming language