WeixiangYan/CodeTransOcean huggingface dataset:
Task: Lah numbers



C#: using System;
using System.Linq;
using System.Numerics;

namespace LahNumbers {
    class Program {
        static BigInteger Factorial(BigInteger n) {
            if (n == 0) return 1;
            BigInteger res = 1;
            while (n > 0) {
                res *= n--;
            }
            return res;
        }

        static BigInteger Lah(BigInteger n, BigInteger k) {
            if (k == 1) return Factorial(n);
            if (k == n) return 1;
            if (k > n) return 0;
            if (k < 1 || n < 1) return 0;
            return (Factorial(n) * Factorial(n - 1)) / (Factorial(k) * Factorial(k - 1)) / Factorial(n - k);
        }

        static void Main() {
            Console.WriteLine("Unsigned Lah numbers: L(n, k):");
            Console.Write("n/k ");
            foreach (var i in Enumerable.Range(0, 13)) {
                Console.Write("{0,10} ", i);
            }
            Console.WriteLine();
            foreach (var row in Enumerable.Range(0, 13)) {
                Console.Write("{0,-3}", row);
                foreach (var i in Enumerable.Range(0, row + 1)) {
                    var l = Lah(row, i);
                    Console.Write("{0,11}", l);
                }
                Console.WriteLine();
            }
            Console.WriteLine("\nMaximum value from the L(100, *) row:");
            var maxVal = Enumerable.Range(0, 100).Select(a => Lah(100, a)).Max();
            Console.WriteLine(maxVal);
        }
    }
}



Java: import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class LahNumbers {

    public static void main(String[] args) {
        System.out.println("Show the unsigned Lah numbers up to n = 12:");
        for ( int n = 0 ; n <= 12 ; n++ ) {
            System.out.printf("%5s", n);
            for ( int k = 0 ; k <= n ; k++ ) {
                System.out.printf("%12s", lahNumber(n, k));
            }
            System.out.printf("%n");
        }
        
        System.out.println("Show the maximum value of L(100, k):");
        int n = 100;
        BigInteger max = BigInteger.ZERO;
        for ( int k = 0 ; k <= n ; k++ ) {
            max = max.max(lahNumber(n, k));
        }
        System.out.printf("%s", max);
    }
    
    private static Map<String,BigInteger> CACHE = new HashMap<>();
    
    private static BigInteger lahNumber(int n, int k) {
        String key = n + "," + k;
        if ( CACHE.containsKey(key) ) {
            return CACHE.get(key);
        }
        
        
        BigInteger result;
        if ( n == 0 && k == 0 ) {
            result = BigInteger.ONE;
        }
        else if ( k == 0 ) {
            result = BigInteger.ZERO;
        }
        else if ( k > n ) {
            result = BigInteger.ZERO;
        }
        else if ( n == 1 && k == 1 ) {
            result = BigInteger.ONE;
        }
        else {
            result = BigInteger.valueOf(n-1+k).multiply(lahNumber(n-1,k)).add(lahNumber(n-1,k-1));
        }
        
        CACHE.put(key, result);
        
        return result;
    }

}
Task: Lah numbers



C#: using System;
using System.Linq;
using System.Numerics;

namespace LahNumbers {
    class Program {
        static BigInteger Factorial(BigInteger n) {
            if (n == 0) return 1;
            BigInteger res = 1;
            while (n > 0) {
                res *= n--;
            }
            return res;
        }

        static BigInteger Lah(BigInteger n, BigInteger k) {
            if (k == 1) return Factorial(n);
            if (k == n) return 1;
            if (k > n) return 0;
            if (k < 1 || n < 1) return 0;
            return (Factorial(n) * Factorial(n - 1)) / (Factorial(k) * Factorial(k - 1)) / Factorial(n - k);
        }

        static void Main() {
            Console.WriteLine("Unsigned Lah numbers: L(n, k):");
            Console.Write("n/k ");
            foreach (var i in Enumerable.Range(0, 13)) {
                Console.Write("{0,10} ", i);
            }
            Console.WriteLine();
            foreach (var row in Enumerable.Range(0, 13)) {
                Console.Write("{0,-3}", row);
                foreach (var i in Enumerable.Range(0, row + 1)) {
                    var l = Lah(row, i);
                    Console.Write("{0,11}", l);
                }
                Console.WriteLine();
            }
            Console.WriteLine("\nMaximum value from the L(100, *) row:");
            var maxVal = Enumerable.Range(0, 100).Select(a => Lah(100, a)).Max();
            Console.WriteLine(maxVal);
        }
    }
}





Python: def factorial(n):
    if n == 0:
        return 1
    res = 1
    while n > 0:
        res *= n
        n -= 1
    return res

def lah(n,k):
    if k == 1:
        return factorial(n)
    if k == n:
        return 1
    if k > n:
        return 0
    if k < 1 or n < 1:
        return 0
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k)

def main():
    print "Unsigned Lah numbers: L(n, k):"
    print "n/k ",
    for i in xrange(13):
        print "%11d" % i,
    print
    for row in xrange(13):
        print "%-4d" % row,
        for i in xrange(row + 1):
            l = lah(row, i)
            print "%11d" % l,
        print
    print "\nMaximum value from the L(100, *) row:"
    maxVal = max([lah(100, a) for a in xrange(100)])
    print maxVal

main()
Task: Lah numbers



C#: using System;
using System.Linq;
using System.Numerics;

namespace LahNumbers {
    class Program {
        static BigInteger Factorial(BigInteger n) {
            if (n == 0) return 1;
            BigInteger res = 1;
            while (n > 0) {
                res *= n--;
            }
            return res;
        }

        static BigInteger Lah(BigInteger n, BigInteger k) {
            if (k == 1) return Factorial(n);
            if (k == n) return 1;
            if (k > n) return 0;
            if (k < 1 || n < 1) return 0;
            return (Factorial(n) * Factorial(n - 1)) / (Factorial(k) * Factorial(k - 1)) / Factorial(n - k);
        }

        static void Main() {
            Console.WriteLine("Unsigned Lah numbers: L(n, k):");
            Console.Write("n/k ");
            foreach (var i in Enumerable.Range(0, 13)) {
                Console.Write("{0,10} ", i);
            }
            Console.WriteLine();
            foreach (var row in Enumerable.Range(0, 13)) {
                Console.Write("{0,-3}", row);
                foreach (var i in Enumerable.Range(0, row + 1)) {
                    var l = Lah(row, i);
                    Console.Write("{0,11}", l);
                }
                Console.WriteLine();
            }
            Console.WriteLine("\nMaximum value from the L(100, *) row:");
            var maxVal = Enumerable.Range(0, 100).Select(a => Lah(100, a)).Max();
            Console.WriteLine(maxVal);
        }
    }
}






VB: 

    Function F(i,n)
        Dim c: c=CCur(i): If n>Len(c) Then F=Space(n-Len(c))&c Else F=c
    End Function 

    Function Fact(ByVal n)
        Dim res
        If n=0 Then
            Fact = 1
        Else
            res = 1
            While n>0
                res = res*n
                n = n-1
            Wend
            Fact = res
        End If
    End Function 
 
    Function Lah(n, k)
        If k=1 Then
            Lah = Fact(n)
        ElseIf k=n Then
            Lah = 1
        ElseIf k>n Then
            Lah=0
        ElseIf k < 1 Or n < 1 Then
            Lah = 0
        Else
            Lah = (Fact(n) * Fact(n-1)) / (Fact(k) * Fact(k-1)) / Fact(n-k)
        End If
    End Function 
 
    Sub Main()
        ns=12: p=10
        WScript.Echo "Unsigned Lah numbers: Lah(n,k):"
        buf = "n/k "
        For k=1 To ns
           buf = buf & F(k,p) & " "
        Next 
        WScript.Echo buf
        For n=1 To ns
           buf = F(n,3) & " "
            For k=1 To n
                l = Lah(n,k)
                buf = buf & F(l,p) & " "
            Next 
            WScript.Echo buf
        Next 
    End Sub 

    Main()
Task: Lah numbers




Go: package main

import (
    "fmt"
    "math/big"
)

func main() {
    limit := 100
    last := 12
    unsigned := true
    l := make([][]*big.Int, limit+1)
    for n := 0; n <= limit; n++ {
        l[n] = make([]*big.Int, limit+1)
        for k := 0; k <= limit; k++ {
            l[n][k] = new(big.Int)
        }
        l[n][n].SetInt64(int64(1))
        if n != 1 {
            l[n][1].MulRange(int64(2), int64(n))
        }
    }
    var t big.Int
    for n := 1; n <= limit; n++ {
        for k := 1; k <= n; k++ {
            t.Mul(l[n][1], l[n-1][1])
            t.Quo(&t, l[k][1])
            t.Quo(&t, l[k-1][1])
            t.Quo(&t, l[n-k][1])
            l[n][k].Set(&t)
            if !unsigned && (n%2 == 1) {
                l[n][k].Neg(l[n][k])
            }
        }
    }
    fmt.Println("Unsigned Lah numbers: l(n, k):")
    fmt.Printf("n/k")
    for i := 0; i <= last; i++ {
        fmt.Printf("%10d ", i)
    }
    fmt.Printf("\n--")
    for i := 0; i <= last; i++ {
        fmt.Printf("-----------")
    }
    fmt.Println()
    for n := 0; n <= last; n++ {
        fmt.Printf("%2d ", n)
        for k := 0; k <= n; k++ {
            fmt.Printf("%10d ", l[n][k])
        }
        fmt.Println()
    }
    fmt.Println("\nMaximum value from the l(100, *) row:")
    max := new(big.Int).Set(l[limit][0])
    for k := 1; k <= limit; k++ {
        if l[limit][k].Cmp(max) > 0 {
            max.Set(l[limit][k])
        }
    }
    fmt.Println(max)
    fmt.Printf("which has %d digits.\n", len(max.String()))
}


Java: import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class LahNumbers {

    public static void main(String[] args) {
        System.out.println("Show the unsigned Lah numbers up to n = 12:");
        for ( int n = 0 ; n <= 12 ; n++ ) {
            System.out.printf("%5s", n);
            for ( int k = 0 ; k <= n ; k++ ) {
                System.out.printf("%12s", lahNumber(n, k));
            }
            System.out.printf("%n");
        }
        
        System.out.println("Show the maximum value of L(100, k):");
        int n = 100;
        BigInteger max = BigInteger.ZERO;
        for ( int k = 0 ; k <= n ; k++ ) {
            max = max.max(lahNumber(n, k));
        }
        System.out.printf("%s", max);
    }
    
    private static Map<String,BigInteger> CACHE = new HashMap<>();
    
    private static BigInteger lahNumber(int n, int k) {
        String key = n + "," + k;
        if ( CACHE.containsKey(key) ) {
            return CACHE.get(key);
        }
        
        
        BigInteger result;
        if ( n == 0 && k == 0 ) {
            result = BigInteger.ONE;
        }
        else if ( k == 0 ) {
            result = BigInteger.ZERO;
        }
        else if ( k > n ) {
            result = BigInteger.ZERO;
        }
        else if ( n == 1 && k == 1 ) {
            result = BigInteger.ONE;
        }
        else {
            result = BigInteger.valueOf(n-1+k).multiply(lahNumber(n-1,k)).add(lahNumber(n-1,k-1));
        }
        
        CACHE.put(key, result);
        
        return result;
    }

}
Task: Lah numbers





Java: import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class LahNumbers {

    public static void main(String[] args) {
        System.out.println("Show the unsigned Lah numbers up to n = 12:");
        for ( int n = 0 ; n <= 12 ; n++ ) {
            System.out.printf("%5s", n);
            for ( int k = 0 ; k <= n ; k++ ) {
                System.out.printf("%12s", lahNumber(n, k));
            }
            System.out.printf("%n");
        }
        
        System.out.println("Show the maximum value of L(100, k):");
        int n = 100;
        BigInteger max = BigInteger.ZERO;
        for ( int k = 0 ; k <= n ; k++ ) {
            max = max.max(lahNumber(n, k));
        }
        System.out.printf("%s", max);
    }
    
    private static Map<String,BigInteger> CACHE = new HashMap<>();
    
    private static BigInteger lahNumber(int n, int k) {
        String key = n + "," + k;
        if ( CACHE.containsKey(key) ) {
            return CACHE.get(key);
        }
        
        
        BigInteger result;
        if ( n == 0 && k == 0 ) {
            result = BigInteger.ONE;
        }
        else if ( k == 0 ) {
            result = BigInteger.ZERO;
        }
        else if ( k > n ) {
            result = BigInteger.ZERO;
        }
        else if ( n == 1 && k == 1 ) {
            result = BigInteger.ONE;
        }
        else {
            result = BigInteger.valueOf(n-1+k).multiply(lahNumber(n-1,k)).add(lahNumber(n-1,k-1));
        }
        
        CACHE.put(key, result);
        
        return result;
    }

}



Python: def factorial(n):
    if n == 0:
        return 1
    res = 1
    while n > 0:
        res *= n
        n -= 1
    return res

def lah(n,k):
    if k == 1:
        return factorial(n)
    if k == n:
        return 1
    if k > n:
        return 0
    if k < 1 or n < 1:
        return 0
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k)

def main():
    print "Unsigned Lah numbers: L(n, k):"
    print "n/k ",
    for i in xrange(13):
        print "%11d" % i,
    print
    for row in xrange(13):
        print "%-4d" % row,
        for i in xrange(row + 1):
            l = lah(row, i)
            print "%11d" % l,
        print
    print "\nMaximum value from the L(100, *) row:"
    maxVal = max([lah(100, a) for a in xrange(100)])
    print maxVal

main()
Task: Lah numbers





Java: import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class LahNumbers {

    public static void main(String[] args) {
        System.out.println("Show the unsigned Lah numbers up to n = 12:");
        for ( int n = 0 ; n <= 12 ; n++ ) {
            System.out.printf("%5s", n);
            for ( int k = 0 ; k <= n ; k++ ) {
                System.out.printf("%12s", lahNumber(n, k));
            }
            System.out.printf("%n");
        }
        
        System.out.println("Show the maximum value of L(100, k):");
        int n = 100;
        BigInteger max = BigInteger.ZERO;
        for ( int k = 0 ; k <= n ; k++ ) {
            max = max.max(lahNumber(n, k));
        }
        System.out.printf("%s", max);
    }
    
    private static Map<String,BigInteger> CACHE = new HashMap<>();
    
    private static BigInteger lahNumber(int n, int k) {
        String key = n + "," + k;
        if ( CACHE.containsKey(key) ) {
            return CACHE.get(key);
        }
        
        
        BigInteger result;
        if ( n == 0 && k == 0 ) {
            result = BigInteger.ONE;
        }
        else if ( k == 0 ) {
            result = BigInteger.ZERO;
        }
        else if ( k > n ) {
            result = BigInteger.ZERO;
        }
        else if ( n == 1 && k == 1 ) {
            result = BigInteger.ONE;
        }
        else {
            result = BigInteger.valueOf(n-1+k).multiply(lahNumber(n-1,k)).add(lahNumber(n-1,k-1));
        }
        
        CACHE.put(key, result);
        
        return result;
    }

}




VB: 

    Function F(i,n)
        Dim c: c=CCur(i): If n>Len(c) Then F=Space(n-Len(c))&c Else F=c
    End Function 

    Function Fact(ByVal n)
        Dim res
        If n=0 Then
            Fact = 1
        Else
            res = 1
            While n>0
                res = res*n
                n = n-1
            Wend
            Fact = res
        End If
    End Function 
 
    Function Lah(n, k)
        If k=1 Then
            Lah = Fact(n)
        ElseIf k=n Then
            Lah = 1
        ElseIf k>n Then
            Lah=0
        ElseIf k < 1 Or n < 1 Then
            Lah = 0
        Else
            Lah = (Fact(n) * Fact(n-1)) / (Fact(k) * Fact(k-1)) / Fact(n-k)
        End If
    End Function 
 
    Sub Main()
        ns=12: p=10
        WScript.Echo "Unsigned Lah numbers: Lah(n,k):"
        buf = "n/k "
        For k=1 To ns
           buf = buf & F(k,p) & " "
        Next 
        WScript.Echo buf
        For n=1 To ns
           buf = F(n,3) & " "
            For k=1 To n
                l = Lah(n,k)
                buf = buf & F(l,p) & " "
            Next 
            WScript.Echo buf
        Next 
    End Sub 

    Main()
Task: Lah numbers




Go: package main

import (
    "fmt"
    "math/big"
)

func main() {
    limit := 100
    last := 12
    unsigned := true
    l := make([][]*big.Int, limit+1)
    for n := 0; n <= limit; n++ {
        l[n] = make([]*big.Int, limit+1)
        for k := 0; k <= limit; k++ {
            l[n][k] = new(big.Int)
        }
        l[n][n].SetInt64(int64(1))
        if n != 1 {
            l[n][1].MulRange(int64(2), int64(n))
        }
    }
    var t big.Int
    for n := 1; n <= limit; n++ {
        for k := 1; k <= n; k++ {
            t.Mul(l[n][1], l[n-1][1])
            t.Quo(&t, l[k][1])
            t.Quo(&t, l[k-1][1])
            t.Quo(&t, l[n-k][1])
            l[n][k].Set(&t)
            if !unsigned && (n%2 == 1) {
                l[n][k].Neg(l[n][k])
            }
        }
    }
    fmt.Println("Unsigned Lah numbers: l(n, k):")
    fmt.Printf("n/k")
    for i := 0; i <= last; i++ {
        fmt.Printf("%10d ", i)
    }
    fmt.Printf("\n--")
    for i := 0; i <= last; i++ {
        fmt.Printf("-----------")
    }
    fmt.Println()
    for n := 0; n <= last; n++ {
        fmt.Printf("%2d ", n)
        for k := 0; k <= n; k++ {
            fmt.Printf("%10d ", l[n][k])
        }
        fmt.Println()
    }
    fmt.Println("\nMaximum value from the l(100, *) row:")
    max := new(big.Int).Set(l[limit][0])
    for k := 1; k <= limit; k++ {
        if l[limit][k].Cmp(max) > 0 {
            max.Set(l[limit][k])
        }
    }
    fmt.Println(max)
    fmt.Printf("which has %d digits.\n", len(max.String()))
}




Python: def factorial(n):
    if n == 0:
        return 1
    res = 1
    while n > 0:
        res *= n
        n -= 1
    return res

def lah(n,k):
    if k == 1:
        return factorial(n)
    if k == n:
        return 1
    if k > n:
        return 0
    if k < 1 or n < 1:
        return 0
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k)

def main():
    print "Unsigned Lah numbers: L(n, k):"
    print "n/k ",
    for i in xrange(13):
        print "%11d" % i,
    print
    for row in xrange(13):
        print "%-4d" % row,
        for i in xrange(row + 1):
            l = lah(row, i)
            print "%11d" % l,
        print
    print "\nMaximum value from the L(100, *) row:"
    maxVal = max([lah(100, a) for a in xrange(100)])
    print maxVal

main()
Task: Lah numbers




Go: package main

import (
    "fmt"
    "math/big"
)

func main() {
    limit := 100
    last := 12
    unsigned := true
    l := make([][]*big.Int, limit+1)
    for n := 0; n <= limit; n++ {
        l[n] = make([]*big.Int, limit+1)
        for k := 0; k <= limit; k++ {
            l[n][k] = new(big.Int)
        }
        l[n][n].SetInt64(int64(1))
        if n != 1 {
            l[n][1].MulRange(int64(2), int64(n))
        }
    }
    var t big.Int
    for n := 1; n <= limit; n++ {
        for k := 1; k <= n; k++ {
            t.Mul(l[n][1], l[n-1][1])
            t.Quo(&t, l[k][1])
            t.Quo(&t, l[k-1][1])
            t.Quo(&t, l[n-k][1])
            l[n][k].Set(&t)
            if !unsigned && (n%2 == 1) {
                l[n][k].Neg(l[n][k])
            }
        }
    }
    fmt.Println("Unsigned Lah numbers: l(n, k):")
    fmt.Printf("n/k")
    for i := 0; i <= last; i++ {
        fmt.Printf("%10d ", i)
    }
    fmt.Printf("\n--")
    for i := 0; i <= last; i++ {
        fmt.Printf("-----------")
    }
    fmt.Println()
    for n := 0; n <= last; n++ {
        fmt.Printf("%2d ", n)
        for k := 0; k <= n; k++ {
            fmt.Printf("%10d ", l[n][k])
        }
        fmt.Println()
    }
    fmt.Println("\nMaximum value from the l(100, *) row:")
    max := new(big.Int).Set(l[limit][0])
    for k := 1; k <= limit; k++ {
        if l[limit][k].Cmp(max) > 0 {
            max.Set(l[limit][k])
        }
    }
    fmt.Println(max)
    fmt.Printf("which has %d digits.\n", len(max.String()))
}





VB: 

    Function F(i,n)
        Dim c: c=CCur(i): If n>Len(c) Then F=Space(n-Len(c))&c Else F=c
    End Function 

    Function Fact(ByVal n)
        Dim res
        If n=0 Then
            Fact = 1
        Else
            res = 1
            While n>0
                res = res*n
                n = n-1
            Wend
            Fact = res
        End If
    End Function 
 
    Function Lah(n, k)
        If k=1 Then
            Lah = Fact(n)
        ElseIf k=n Then
            Lah = 1
        ElseIf k>n Then
            Lah=0
        ElseIf k < 1 Or n < 1 Then
            Lah = 0
        Else
            Lah = (Fact(n) * Fact(n-1)) / (Fact(k) * Fact(k-1)) / Fact(n-k)
        End If
    End Function 
 
    Sub Main()
        ns=12: p=10
        WScript.Echo "Unsigned Lah numbers: Lah(n,k):"
        buf = "n/k "
        For k=1 To ns
           buf = buf & F(k,p) & " "
        Next 
        WScript.Echo buf
        For n=1 To ns
           buf = F(n,3) & " "
            For k=1 To n
                l = Lah(n,k)
                buf = buf & F(l,p) & " "
            Next 
            WScript.Echo buf
        Next 
    End Sub 

    Main()
Task: Lah numbers







Python: def factorial(n):
    if n == 0:
        return 1
    res = 1
    while n > 0:
        res *= n
        n -= 1
    return res

def lah(n,k):
    if k == 1:
        return factorial(n)
    if k == n:
        return 1
    if k > n:
        return 0
    if k < 1 or n < 1:
        return 0
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k)

def main():
    print "Unsigned Lah numbers: L(n, k):"
    print "n/k ",
    for i in xrange(13):
        print "%11d" % i,
    print
    for row in xrange(13):
        print "%-4d" % row,
        for i in xrange(row + 1):
            l = lah(row, i)
            print "%11d" % l,
        print
    print "\nMaximum value from the L(100, *) row:"
    maxVal = max([lah(100, a) for a in xrange(100)])
    print maxVal

main()


VB: 

    Function F(i,n)
        Dim c: c=CCur(i): If n>Len(c) Then F=Space(n-Len(c))&c Else F=c
    End Function 

    Function Fact(ByVal n)
        Dim res
        If n=0 Then
            Fact = 1
        Else
            res = 1
            While n>0
                res = res*n
                n = n-1
            Wend
            Fact = res
        End If
    End Function 
 
    Function Lah(n, k)
        If k=1 Then
            Lah = Fact(n)
        ElseIf k=n Then
            Lah = 1
        ElseIf k>n Then
            Lah=0
        ElseIf k < 1 Or n < 1 Then
            Lah = 0
        Else
            Lah = (Fact(n) * Fact(n-1)) / (Fact(k) * Fact(k-1)) / Fact(n-k)
        End If
    End Function 
 
    Sub Main()
        ns=12: p=10
        WScript.Echo "Unsigned Lah numbers: Lah(n,k):"
        buf = "n/k "
        For k=1 To ns
           buf = buf & F(k,p) & " "
        Next 
        WScript.Echo buf
        For n=1 To ns
           buf = F(n,3) & " "
            For k=1 To n
                l = Lah(n,k)
                buf = buf & F(l,p) & " "
            Next 
            WScript.Echo buf
        Next 
    End Sub 

    Main()