Lah numbers: Difference between revisions

Content added Content deleted
(Added Dyalect)
m (syntax highlighting fixup automation)
Line 40: Line 40:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F lah(BigInt n, BigInt k)
<syntaxhighlight lang="11l">F lah(BigInt n, BigInt k)
I k == 1
I k == 1
R factorial(n)
R factorial(n)
Line 64: Line 64:
print("\nMaximum value from the L(100, *) row:")
print("\nMaximum value from the L(100, *) row:")
V maxVal = max((0.<100).map(a -> lah(100, a)))
V maxVal = max((0.<100).map(a -> lah(100, a)))
print(maxVal)</lang>
print(maxVal)</syntaxhighlight>


{{out}}
{{out}}
Line 92: Line 92:
{{Trans|ALGOL W}}
{{Trans|ALGOL W}}
Uses Algol 68G's LONG LONG INT which has programmer-specifiable precision, so can find Lah numbers with n = 100 and need not use the scaling "trick" used by the Algol W sample.
Uses Algol 68G's LONG LONG INT which has programmer-specifiable precision, so can find Lah numbers with n = 100 and need not use the scaling "trick" used by the Algol W sample.
<lang algol68>BEGIN # calculate Lah numbers upto L( 12, 12 ) #
<syntaxhighlight lang="algol68">BEGIN # calculate Lah numbers upto L( 12, 12 ) #
PR precision 400 PR # set the precision for LONG LONG INT #
PR precision 400 PR # set the precision for LONG LONG INT #
# returns Lah Number L( n, k ), f must be a table of factorials to at least n #
# returns Lah Number L( n, k ), f must be a table of factorials to at least n #
Line 138: Line 138:
OD;
OD;
print( ( "maximum Lah number for n = 100: ", whole( max 100, 0 ), newline ) )
print( ( "maximum Lah number for n = 100: ", whole( max 100, 0 ), newline ) )
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 162: Line 162:
<br>
<br>
As L(12,2), L(12,3) and L(12,4) are too large for signed 32 bit integers, this sample scales the result by an appropriate power of 10 to enable the table to be printed up to L(12,12). Luckily, the problematic L(12,k) values all have at least 2 trailing zeros.
As L(12,2), L(12,3) and L(12,4) are too large for signed 32 bit integers, this sample scales the result by an appropriate power of 10 to enable the table to be printed up to L(12,12). Luckily, the problematic L(12,k) values all have at least 2 trailing zeros.
<lang algolw>begin % calculate Lah numbers upto L( 12, 12 ) %
<syntaxhighlight lang="algolw">begin % calculate Lah numbers upto L( 12, 12 ) %
% sets lahNumber to L( n, k ), lahScale is returned as the power of 10 %
% sets lahNumber to L( n, k ), lahScale is returned as the power of 10 %
% lahNumber should be multiplied by %
% lahNumber should be multiplied by %
Line 216: Line 216:
end for_k
end for_k
end for_n
end for_n
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 238: Line 238:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>factorial: function [n]-> product 1..n
<syntaxhighlight lang="rebol">factorial: function [n]-> product 1..n


lah: function [n,k][
lah: function [n,k][
Line 252: Line 252:
loop 1..12 'x [
loop 1..12 'x [
print @[pad to :string x 3] ++ map to [:string] map 1..12 'y -> lah x y 's -> pad s 10
print @[pad to :string x 3] ++ map to [:string] map 1..12 'y -> lah x y 's -> pad s 10
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 272: Line 272:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f LAH_NUMBERS.AWK
# syntax: GAWK -f LAH_NUMBERS.AWK
# converted from C
# converted from C
Line 304: Line 304:
return (factorial(n) * factorial(n-1)) / (factorial(k) * factorial(k-1)) / factorial(n-k)
return (factorial(n) * factorial(n-1)) / (factorial(k) * factorial(k-1)) / factorial(n-k)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 330: Line 330:


The last line builds a table where the rows represent <code>n</code> and columns represent <code>k</code>.
The last line builds a table where the rows represent <code>n</code> and columns represent <code>k</code>.
<lang bqn>F ← (≥⟜0)◶⟨0,×´1+↕⟩
<syntaxhighlight lang="bqn">F ← (≥⟜0)◶⟨0,×´1+↕⟩
Lah ← {
Lah ← {
𝕨 𝕊 0: 0;
𝕨 𝕊 0: 0;
Line 339: Line 339:
}
}


•Show Lah⌜˜↕12</lang><lang>┌─
•Show Lah⌜˜↕12</syntaxhighlight><syntaxhighlight lang="text">┌─
╵ 0 0 0 0 0 0 0 0 0 0 0 0
╵ 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0
Line 352: Line 352:
0 3628800 16329600 21772800 12700800 3810240 635040 60480 3240 90 1 0
0 3628800 16329600 21772800 12700800 3810240 635040 60480 3240 90 1 0
0 39916800 199584000 299376000 199584000 69854400 13970880 1663200 118800 4950 110 1
0 39916800 199584000 299376000 199584000 69854400 13970880 1663200 118800 4950 110 1
┘</lang>
┘</syntaxhighlight>
[https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgKOKJpeKfnDAp4pe24p+oMCzDl8K0MSvihpXin6kKTGFoIOKGkCB7CiAg8J2VqCDwnZWKIDA6IDA7CiAgMCDwnZWKIPCdlak6IDA7CiAg8J2VqCDwnZWKIDE6IEYg8J2VqDsKICBuIPCdlYogazoKICAobj1rKeKKkeKfqCgobiDDl+KXi0Ygbi0xKSDDtyBrIMOX4peLRiBrLTEpICgwPeKKoinil7bDt+KAvzAgRiBuLWssIDHin6kKfQoK4oCiU2hvdyBMYWjijJzLnOKGlTEy Try It!]
[https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgKOKJpeKfnDAp4pe24p+oMCzDl8K0MSvihpXin6kKTGFoIOKGkCB7CiAg8J2VqCDwnZWKIDA6IDA7CiAgMCDwnZWKIPCdlak6IDA7CiAg8J2VqCDwnZWKIDE6IEYg8J2VqDsKICBuIPCdlYogazoKICAobj1rKeKKkeKfqCgobiDDl+KXi0Ygbi0xKSDDtyBrIMOX4peLRiBrLTEpICgwPeKKoinil7bDt+KAvzAgRiBuLWssIDHin6kKfQoK4oCiU2hvdyBMYWjijJzLnOKGlTEy Try It!]


=={{header|C}}==
=={{header|C}}==
{{trans|D}}
{{trans|D}}
<lang c>#include <stdint.h>
<syntaxhighlight lang="c">#include <stdint.h>
#include <stdio.h>
#include <stdio.h>


Line 394: Line 394:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 414: Line 414:
=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{trans|D}}
{{trans|D}}
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Linq;
using System.Numerics;
using System.Numerics;
Line 457: Line 457:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>0 1
<pre>0 1
Line 478: Line 478:
=={{header|C++}}==
=={{header|C++}}==
{{libheader|GMP}}
{{libheader|GMP}}
<lang cpp>// Reference: https://en.wikipedia.org/wiki/Lah_number#Identities_and_relations
<syntaxhighlight lang="cpp">// Reference: https://en.wikipedia.org/wiki/Lah_number#Identities_and_relations


#include <algorithm>
#include <algorithm>
Line 531: Line 531:
std::cout << max << '\n';
std::cout << max << '\n';
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 555: Line 555:
=={{header|D}}==
=={{header|D}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang d>import std.algorithm : map;
<syntaxhighlight lang="d">import std.algorithm : map;
import std.bigint;
import std.bigint;
import std.range;
import std.range;
Line 609: Line 609:
auto lambda = (int a) => lah(BigInt(100), BigInt(a));
auto lambda = (int a) => lah(BigInt(100), BigInt(a));
writeln(iota(0, 100).map!lambda.max);
writeln(iota(0, 100).map!lambda.max);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 632: Line 632:
=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang dyalect>func fact(n) =>
<syntaxhighlight lang="dyalect">func fact(n) =>
n is 0 ? 1 : (n^-1..<0).Fold(1, (acc, val) => acc * val)
n is 0 ? 1 : (n^-1..<0).Fold(1, (acc, val) => acc * val)


Line 650: Line 650:
(0..row).ForEach(i => lah(row, i) >> "{0,11}".Format >> print(terminator: ""))
(0..row).ForEach(i => lah(row, i) >> "{0,11}".Format >> print(terminator: ""))
print("")
print("")
})</lang>
})</syntaxhighlight>


{{out}}
{{out}}
Line 672: Line 672:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 development version 2019-07-10}}
{{works with|Factor|0.99 development version 2019-07-10}}
<lang factor>USING: combinators combinators.short-circuit formatting infix io
<syntaxhighlight lang="factor">USING: combinators combinators.short-circuit formatting infix io
kernel locals math math.factorials math.ranges prettyprint
kernel locals math math.factorials math.ranges prettyprint
sequences ;
sequences ;
Line 703: Line 703:


"Maximum value from the 100 _ lah row:" print
"Maximum value from the 100 _ lah row:" print
100 [0,b] [ 100 swap lah ] map supremum .</lang>
100 [0,b] [ 100 swap lah ] map supremum .</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 727: Line 727:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang FreeBASIC>function factorial( n as uinteger ) as ulongint
<syntaxhighlight lang="freebasic">function factorial( n as uinteger ) as ulongint
if n = 0 then return 1
if n = 0 then return 1
return n*factorial(n-1)
return n*factorial(n-1)
Line 761: Line 761:
next k
next k
print outstr
print outstr
next n</lang>
next n</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 792: Line 792:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 853: Line 853:
fmt.Println(max)
fmt.Println(max)
fmt.Printf("which has %d digits.\n", len(max.String()))
fmt.Printf("which has %d digits.\n", len(max.String()))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 880: Line 880:
=={{header|Haskell}}==
=={{header|Haskell}}==
{{trans|Python}}
{{trans|Python}}
<lang haskell>import Text.Printf (printf)
<syntaxhighlight lang="haskell">import Text.Printf (printf)
import Control.Monad (when)
import Control.Monad (when)
Line 909: Line 909:
printf "\nMaximum value from the L(100, *) row:\n%d\n"
printf "\nMaximum value from the L(100, *) row:\n%d\n"
(maximum $ lah 100 <$> ([0..100] :: [Integer]))
(maximum $ lah 100 <$> ([0..100] :: [Integer]))
where zeroToTwelve = [0..12]</lang>
where zeroToTwelve = [0..12]</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 931: Line 931:


=={{header|J}}==
=={{header|J}}==
<syntaxhighlight lang="j">
<lang J>
NB. use: k lah n
NB. use: k lah n
lah=: ! :(!&<: * %&!~)&x: NB. `%~' is shorter than `*inv'
lah=: ! :(!&<: * %&!~)&x: NB. `%~' is shorter than `*inv'
Line 949: Line 949:
extend_precision =: x: Monad
extend_precision =: x: Monad
wordy_lah =: ((combinations but_1st decrement) times (into but_1st factorial))but_1st extend_precision Dyad
wordy_lah =: ((combinations but_1st decrement) times (into but_1st factorial))but_1st extend_precision Dyad
</syntaxhighlight>
</lang>
<pre>
<pre>
lah&>~table~>:i.12
lah&>~table~>:i.12
Line 984: Line 984:


=={{header|Java}}==
=={{header|Java}}==
<lang java>
<syntaxhighlight lang="java">
import java.math.BigInteger;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashMap;
Line 1,042: Line 1,042:


}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,070: Line 1,070:
but gojq is required to produce the precise maximum value.
but gojq is required to produce the precise maximum value.


<lang jq>## Generic functions
<syntaxhighlight lang="jq">## Generic functions


def factorial: reduce range(2;.+1) as $i (1; . * $i);
def factorial: reduce range(2;.+1) as $i (1; . * $i);
Line 1,098: Line 1,098:


def lah($n; $k): lah($n;$k;false);
def lah($n; $k): lah($n;$k;false);
</syntaxhighlight>
</lang>
'''The task'''
'''The task'''
<lang jq>def printlahtable($kmax):
<syntaxhighlight lang="jq">def printlahtable($kmax):
def pad: lpad(12);
def pad: lpad(12);
reduce range(0;$kmax+1) as $k ("n/k"|lpad(4); . + ($k|pad)),
reduce range(0;$kmax+1) as $k ("n/k"|lpad(4); . + ($k|pad)),
Line 1,114: Line 1,114:


task
task
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,137: Line 1,137:
=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Combinatorics
<syntaxhighlight lang="julia">using Combinatorics


function lah(n::Integer, k::Integer, signed=false)
function lah(n::Integer, k::Integer, signed=false)
Line 1,169: Line 1,169:


println("\nThe maxiumum of lah(100, _) is: ", maximum(k -> lah(BigInt(100), BigInt(k)), 1:100))
println("\nThe maxiumum of lah(100, _) is: ", maximum(k -> lah(BigInt(100), BigInt(k)), 1:100))
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5 6 7 8 9 10 11 12
Line 1,191: Line 1,191:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Perl}}
{{trans|Perl}}
<lang scala>import java.math.BigInteger
<syntaxhighlight lang="scala">import java.math.BigInteger


fun factorial(n: BigInteger): BigInteger {
fun factorial(n: BigInteger): BigInteger {
Line 1,230: Line 1,230:
println("\nMaximum value from the L(100, *) row:")
println("\nMaximum value from the L(100, *) row:")
println((0..100).map { lah(BigInteger.valueOf(100.toLong()), BigInteger.valueOf(it.toLong())) }.max())
println((0..100).map { lah(BigInteger.valueOf(100.toLong()), BigInteger.valueOf(it.toLong())) }.max())
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 1,252: Line 1,252:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ClearAll[Lah]
<syntaxhighlight lang="mathematica">ClearAll[Lah]
Lah[n_?Positive, 0] := 0
Lah[n_?Positive, 0] := 0
Lah[0, k_?Positive] := 0
Lah[0, k_?Positive] := 0
Line 1,259: Line 1,259:
Lah[n_, k_] := (-1)^n (n! ((n - 1)!))/((k! ((k - 1)!)) ((n - k)!))
Lah[n_, k_] := (-1)^n (n! ((n - 1)!))/((k! ((k - 1)!)) ((n - k)!))
Table[Lah[i, j], {i, 0, 12}, {j, 0, 12}] // Grid
Table[Lah[i, j], {i, 0, 12}, {j, 0, 12}] // Grid
Max[Lah[100, Range[0, 100]]]</lang>
Max[Lah[100, Range[0, 100]]]</syntaxhighlight>
{{out}}
{{out}}
<pre>1 0 0 0 0 0 0 0 0 0 0 0 0
<pre>1 0 0 0 0 0 0 0 0 0 0 0 0
Line 1,281: Line 1,281:
{{trans|Julia}}
{{trans|Julia}}
{{libheader|bignum}}
{{libheader|bignum}}
<lang Nim>import math, strutils
<syntaxhighlight lang="nim">import math, strutils
import bignum
import bignum


Line 1,309: Line 1,309:
let val = lah(n, k)
let val = lah(n, k)
if val > maxval: maxval = val
if val > maxval: maxval = val
echo "\nThe maximum value of lah(100, k) is ", maxval</lang>
echo "\nThe maximum value of lah(100, k) is ", maxval</syntaxhighlight>


{{out}}
{{out}}
Line 1,332: Line 1,332:
{{libheader|ntheory}}
{{libheader|ntheory}}
{{trans|Raku}}
{{trans|Raku}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 1,360: Line 1,360:


say "\nMaximum value from the L(100, *) row:";
say "\nMaximum value from the L(100, *) row:";
say max map { Lah(100,$_) } 0..100;</lang>
say max map { Lah(100,$_) } 0..100;</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 1,384: Line 1,384:
{{libheader|Phix/mpfr}}
{{libheader|Phix/mpfr}}
{{trans|Go}}
{{trans|Go}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,427: Line 1,427:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nThe maximum l(100,k): %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m100</span><span style="color: #0000FF;">)))</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nThe maximum l(100,k): %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m100</span><span style="color: #0000FF;">)))</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,451: Line 1,451:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de fact (N)
<syntaxhighlight lang="picolisp">(de fact (N)
(if (=0 N)
(if (=0 N)
1
1
Line 1,475: Line 1,475:
(prinl "Maximum value from the L(100, *) row:")
(prinl "Maximum value from the L(100, *) row:")
(maxi '((N) (lah 100 N)) (range 0 100))
(maxi '((N) (lah 100 N)) (range 0 100))
(prinl @@)</lang>
(prinl @@)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,498: Line 1,498:
=={{header|Prolog}}==
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{works with|SWI Prolog}}
<lang prolog>% Reference: https://en.wikipedia.org/wiki/Lah_number#Identities_and_relations
<syntaxhighlight lang="prolog">% Reference: https://en.wikipedia.org/wiki/Lah_number#Identities_and_relations


:- dynamic unsigned_lah_number_cache/3.
:- dynamic unsigned_lah_number_cache/3.
Line 1,541: Line 1,541:
writeln('Maximum value of L(n,k) where n = 100:'),
writeln('Maximum value of L(n,k) where n = 100:'),
max_unsigned_lah_number(100, M),
max_unsigned_lah_number(100, M),
writeln(M).</lang>
writeln(M).</syntaxhighlight>


{{out}}
{{out}}
Line 1,563: Line 1,563:


=={{header|Python}}==
=={{header|Python}}==
<lang python>def factorial(n):
<syntaxhighlight lang="python">def factorial(n):
if n == 0:
if n == 0:
return 1
return 1
Line 1,599: Line 1,599:
print maxVal
print maxVal


main()</lang>
main()</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 1,622: Line 1,622:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ table ] is ! ( n --> n )
<syntaxhighlight lang="quackery"> [ table ] is ! ( n --> n )
1
1
101 times
101 times
Line 1,667: Line 1,667:
[ 100 i^ lah
[ 100 i^ lah
2dup < iff nip else drop ]
2dup < iff nip else drop ]
echo</lang>
echo</syntaxhighlight>


{{out}}
{{out}}
Line 1,691: Line 1,691:


=={{header|R}}==
=={{header|R}}==
<lang R>Lah_numbers <- function(n, k, type = "unsigned") {
<syntaxhighlight lang="r">Lah_numbers <- function(n, k, type = "unsigned") {
if (n == k)
if (n == k)
Line 1,722: Line 1,722:


Table
Table
</lang>
</syntaxhighlight>
{{out}}
{{out}}
Line 1,745: Line 1,745:
{{works with|Rakudo|2019.07.1}}
{{works with|Rakudo|2019.07.1}}


<lang perl6>constant @factorial = 1, |[\*] 1..*;
<syntaxhighlight lang="raku" line>constant @factorial = 1, |[\*] 1..*;


sub Lah (Int \n, Int \k) {
sub Lah (Int \n, Int \k) {
Line 1,768: Line 1,768:


say "\nMaximum value from the L(100, *) row:";
say "\nMaximum value from the L(100, *) row:";
say (^100).map( { Lah 100, $_ } ).max;</lang>
say (^100).map( { Lah 100, $_ } ).max;</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 1,793: Line 1,793:


Also, code was added to use memoization of the factorial calculations.
Also, code was added to use memoization of the factorial calculations.
<lang rexx>/*REXX pgm computes & display (unsigned) Stirling numbers of the 3rd kind (Lah numbers).*/
<syntaxhighlight lang="rexx">/*REXX pgm computes & display (unsigned) Stirling numbers of the 3rd kind (Lah numbers).*/
parse arg lim . /*obtain optional argument from the CL.*/
parse arg lim . /*obtain optional argument from the CL.*/
if lim=='' | lim=="," then lim= 12 /*Not specified? Then use the default.*/
if lim=='' | lim=="," then lim= 12 /*Not specified? Then use the default.*/
Line 1,833: Line 1,833:
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: parse arg z; if !.z\==. then return !.z; !=1; do f=2 to z; !=!*f; end; !.z=!; return !
!: parse arg z; if !.z\==. then return !.z; !=1; do f=2 to z; !=!*f; end; !.z=!; return !
maxer: max#.k= max(max#.k, @.n.k); max#.b= max(max#.b, @.n.k); return</lang>
maxer: max#.k= max(max#.k, @.n.k); max#.b= max(max#.b, @.n.k); return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 1,859: Line 1,859:
=={{header|Ruby}}==
=={{header|Ruby}}==
Works with Ruby 3.0 (end-less method; end-less and begin-less range).
Works with Ruby 3.0 (end-less method; end-less and begin-less range).
<lang ruby>def fact(n) = n.zero? ? 1 : 1.upto(n).inject(&:*)
<syntaxhighlight lang="ruby">def fact(n) = n.zero? ? 1 : 1.upto(n).inject(&:*)


def lah(n, k)
def lah(n, k)
Line 1,881: Line 1,881:
puts "\nMaximum value from the L(100, *) row:";
puts "\nMaximum value from the L(100, *) row:";
puts (1..100).map{|a| lah(100,a)}.max
puts (1..100).map{|a| lah(100,a)}.max
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 1,904: Line 1,904:
=={{header|Scheme}}==
=={{header|Scheme}}==
{{works with|Chez Scheme}}
{{works with|Chez Scheme}}
<lang scheme>; Compute the Unsigned Lah number L(n, k).
<syntaxhighlight lang="scheme">; Compute the Unsigned Lah number L(n, k).
(define lah
(define lah
(lambda (n k)
(lambda (n k)
Line 1,938: Line 1,938:
(let ((val (lah 100 k)))
(let ((val (lah 100 k)))
(when (> val max) (set! max val))))
(when (> val max) (set! max val))))
(printf "~d~%" max))</lang>
(printf "~d~%" max))</syntaxhighlight>
{{out}}
{{out}}
<pre>The Unsigned Lah numbers L(n, k) up to L(12, 12):
<pre>The Unsigned Lah numbers L(n, k) up to L(12, 12):
Line 1,959: Line 1,959:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func lah(n, k) {
<syntaxhighlight lang="ruby">func lah(n, k) {
stirling3(n, k)
stirling3(n, k)
#binomial(n-1, k-1) * n!/k! # alternative formula
#binomial(n-1, k-1) * n!/k! # alternative formula
Line 1,980: Line 1,980:
say "\nMaximum value from the L(#{n}, *) row:"
say "\nMaximum value from the L(#{n}, *) row:"
say { lah(n, _) }.map(^n).max
say { lah(n, _) }.map(^n).max
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,007: Line 2,007:
{{trans|Kotlin}}
{{trans|Kotlin}}


<lang swift>import BigInt
<syntaxhighlight lang="swift">import BigInt
import Foundation
import Foundation


Line 2,061: Line 2,061:
let maxLah = (0...100).map({ lah(n: BigInt(100), k: BigInt($0)) }).max()!
let maxLah = (0...100).map({ lah(n: BigInt(100), k: BigInt($0)) }).max()!


print("Maximum value from the L(100, *) row: \(maxLah)")</lang>
print("Maximum value from the L(100, *) row: \(maxLah)")</syntaxhighlight>


{{out}}
{{out}}
Line 2,084: Line 2,084:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang Tcl>proc prod {from to} {
<syntaxhighlight lang="tcl">proc prod {from to} {
set r 1
set r 1
if {$from <= $to} {
if {$from <= $to} {
Line 2,162: Line 2,162:
puts "([string length $maxv] digits, k=$maxk)"
puts "([string length $maxv] digits, k=$maxk)"
}
}
main </lang>
main </syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:83%">Unsigned Lah numbers L(n,k):
<pre style="font-size:83%">Unsigned Lah numbers L(n,k):
Line 2,185: Line 2,185:
=={{header|VBScript}}==
=={{header|VBScript}}==
{{trans|Visual Basic .NET}}
{{trans|Visual Basic .NET}}
<lang vb>' Lah numbers - VBScript - 04/02/2021
<syntaxhighlight lang="vb">' Lah numbers - VBScript - 04/02/2021


Function F(i,n)
Function F(i,n)
Line 2,237: Line 2,237:
End Sub 'Main
End Sub 'Main


Main() </lang>
Main() </syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,258: Line 2,258:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Imports System.Numerics
<syntaxhighlight lang="vbnet">Imports System.Numerics


Module Module1
Module Module1
Line 2,314: Line 2,314:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
<pre>Unsigned Lah numbers: L(n, k):
Line 2,337: Line 2,337:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|go}}
{{trans|go}}
<lang vlang>import math.big
<syntaxhighlight lang="vlang">import math.big


fn main() {
fn main() {
Line 2,394: Line 2,394:
println("which has ${max.str().len} digits.")
println("which has ${max.str().len} digits.")
}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,401: Line 2,401:
=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt


var fact = Fn.new { |n|
var fact = Fn.new { |n|
Line 2,426: Line 2,426:
for (k in 0..n) System.write("%(Fmt.d(10, lah.call(n, k))) ")
for (k in 0..n) System.write("%(Fmt.d(10, lah.call(n, k))) ")
System.print()
System.print()
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,449: Line 2,449:


=={{header|Vala}}==
=={{header|Vala}}==
<lang Vala>uint64 factorial(uint8 n) {
<syntaxhighlight lang="vala">uint64 factorial(uint8 n) {
uint64 res = 1;
uint64 res = 1;
if (n == 0) return res;
if (n == 0) return res;
Line 2,481: Line 2,481:
print("\n");
print("\n");
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:83%">Unsigned Lah numbers: L(n, k):
<pre style="font-size:83%">Unsigned Lah numbers: L(n, k):
Line 2,501: Line 2,501:


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>fcn lah(n,k,fact=fcn(n){ [1..n].reduce('*,1) }){
<syntaxhighlight lang="zkl">fcn lah(n,k,fact=fcn(n){ [1..n].reduce('*,1) }){
if(n==k) return(1);
if(n==k) return(1);
if(k==1) return(fact(n));
if(k==1) return(fact(n));
if(n<1 or k<1) return(0);
if(n<1 or k<1) return(0);
(fact(n)*fact(n - 1)) /(fact(k)*fact(k - 1)) /fact(n - k)
(fact(n)*fact(n - 1)) /(fact(k)*fact(k - 1)) /fact(n - k)
}</lang>
}</syntaxhighlight>
<lang zkl>// calculate entire table (quick), find max, find num digits in max
<syntaxhighlight lang="zkl">// calculate entire table (quick), find max, find num digits in max
N,mx := 12, [1..N].apply(fcn(n){ [1..n].apply(lah.fp(n)) }).flatten() : (0).max(_);
N,mx := 12, [1..N].apply(fcn(n){ [1..n].apply(lah.fp(n)) }).flatten() : (0).max(_);
fmt:="%%%dd".fmt("%d".fmt(mx.numDigits + 1)).fmt; // "%9d".fmt
fmt:="%%%dd".fmt("%d".fmt(mx.numDigits + 1)).fmt; // "%9d".fmt
Line 2,514: Line 2,514:
foreach row in ([0..N]){
foreach row in ([0..N]){
println("%3d".fmt(row), [0..row].pump(String, lah.fp(row), fmt));
println("%3d".fmt(row), [0..row].pump(String, lah.fp(row), fmt));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:83%">
<pre style="font-size:83%">
Line 2,534: Line 2,534:
</pre>
</pre>
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library
<lang zkl>var [const] BI=Import("zklBigNum"); // libGMP
<syntaxhighlight lang="zkl">var [const] BI=Import("zklBigNum"); // libGMP
N=100;
N=100;
L100:=[1..N].apply(lah.fpM("101",BI(N),fcn(n){ BI(n).factorial() }))
L100:=[1..N].apply(lah.fpM("101",BI(N),fcn(n){ BI(n).factorial() }))
.reduce(fcn(m,n){ m.max(n) });
.reduce(fcn(m,n){ m.max(n) });
println("Maximum value from the L(%d, *) row (%d digits):".fmt(N,L100.numDigits));
println("Maximum value from the L(%d, *) row (%d digits):".fmt(N,L100.numDigits));
println(L100);</lang>
println(L100);</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:83%">
<pre style="font-size:83%">