How to resolve the algorithm Lah numbers step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Lah numbers step by step in the Wren programming language

Table of Contents

Problem Statement

Lah numbers, sometimes referred to as Stirling numbers of the third kind, are coefficients of polynomial expansions expressing rising factorials in terms of falling factorials. Unsigned Lah numbers count the number of ways a set of n elements can be partitioned into k non-empty linearly ordered subsets. Lah numbers are closely related to Stirling numbers of the first & second kinds, and may be derived from them. Lah numbers obey the identities and relations:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Lah numbers step by step in the Wren programming language

Source code in the wren programming language

import "./fmt" for Fmt

var fact = Fn.new  { |n|
    if (n < 2) return 1
    var fact = 1
    for (i in 2..n) fact = fact * i
    return fact
}

var lah = Fn.new { |n, k|
    if (k == 1) return fact.call(n)
    if (k == n) return 1
    if (k > n) return 0
    if (k < 1 || n < 1) return 0
    return (fact.call(n) * fact.call(n-1)) / (fact.call(k) * fact.call(k-1)) / fact.call(n-k)
}

System.print("Unsigned Lah numbers: l(n, k):")
System.write("n/k")
for (i in 0..12) Fmt.write("$10d ", i)
System.print("\n" + "-" * 145)
for (n in 0..12) {
    Fmt.write("$2d ", n)
    for (k in 0..n) Fmt.write("$10d ", lah.call(n, k))
    System.print()
}


  

You may also check:How to resolve the algorithm A+B step by step in the EMal programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Erlang programming language
You may also check:How to resolve the algorithm Determine if only one instance is running step by step in the Swift programming language
You may also check:How to resolve the algorithm Box the compass step by step in the Raku programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Astro programming language