How to resolve the algorithm Stirling numbers of the second kind step by step in the 11l 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 11l 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 11l programming language

Source code in the 11l programming language

[(Int, Int) = BigInt] computed

F sterling2(n, k)
   V key = (n, k)

   I key C :computed
      R :computed[key]
   I n == k == 0
      R BigInt(1)
   I (n > 0 & k == 0) | (n == 0 & k > 0)
      R BigInt(0)
   I n == k
      R BigInt(1)
   I k > n
      R BigInt(0)
   V result = k * sterling2(n - 1, k) + sterling2(n - 1, k - 1)
   :computed[key] = result
   R result

print(‘Stirling numbers of the second kind:’)
V MAX = 12
print(‘n/k’.ljust(10), end' ‘’)
L(n) 0 .. MAX
   print(String(n).rjust(10), end' ‘’)
print()
L(n) 0 .. MAX
   print(String(n).ljust(10), end' ‘’)
   L(k) 0 .. n
      print(String(sterling2(n, k)).rjust(10), end' ‘’)
   print()
print(‘The maximum value of S2(100, k) = ’)
BigInt previous = 0
L(k) 1 .. 100
   V current = sterling2(100, k)
   I current > previous
      previous = current
   E
      print("#.\n(#. digits, k = #.)\n".format(previous, String(previous).len, k - 1))
      L.break

  

You may also check:How to resolve the algorithm AKS test for primes step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the Frink programming language
You may also check:How to resolve the algorithm Queue/Definition step by step in the Wren programming language
You may also check:How to resolve the algorithm Hostname step by step in the F# programming language
You may also check:How to resolve the algorithm Digital root step by step in the Perl programming language