kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Frobenius numbers
C: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LIMIT 10000


unsigned int sieve(unsigned int n, unsigned int **list) {
    unsigned char *sieve = calloc(n+1, 1);
    unsigned int i, j, max = 0;
    for (i = 2; i*i <= n; i++)
        if (!sieve[i])
            for (j = i+i; j <= n; j += i)
                sieve[j] = 1;
    for (i = 2; i <= n; i++) max += !sieve[i];
    *list = malloc(max * sizeof(unsigned int));
    for (i = 0, j = 2; j <= n; j++)
        if (!sieve[j]) (*list)[i++] = j;
    free(sieve);
    return i;
}


unsigned int frob(unsigned const int *primes, unsigned int n) {
    return primes[n] * primes[n+1] - primes[n] - primes[n+1];
}

int main() {
    
    unsigned int *primes;
    unsigned int amount = sieve(sqrt(LIMIT)+1, &primes);
    unsigned int i;
    
    for (i=0; i<amount-1; i++) printf("%d\n", frob(primes, i));
    free(primes);
    
    return 0;
}

Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    primes := rcu.Primes(101)
    var frobenius []int
    for i := 0; i < len(primes)-1; i++ {
        frob := primes[i]*primes[i+1] - primes[i] - primes[i+1]
        if frob >= 10000 {
            break
        }
        frobenius = append(frobenius, frob)
    }
    fmt.Println("Frobenius numbers under 10,000:")
    for i, n := range frobenius {
        fmt.Printf("%5s ", rcu.Commatize(n))
        if (i+1)%9 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n\n%d such numbers found.\n", len(frobenius))
}
Task: Frobenius numbers
Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    primes := rcu.Primes(101)
    var frobenius []int
    for i := 0; i < len(primes)-1; i++ {
        frob := primes[i]*primes[i+1] - primes[i] - primes[i+1]
        if frob >= 10000 {
            break
        }
        frobenius = append(frobenius, frob)
    }
    fmt.Println("Frobenius numbers under 10,000:")
    for i, n := range frobenius {
        fmt.Printf("%5s ", rcu.Commatize(n))
        if (i+1)%9 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n\n%d such numbers found.\n", len(frobenius))
}

Java: public class Frobenius {
    public static void main(String[] args) {
        final int limit = 1000000;
        System.out.printf("Frobenius numbers less than %d (asterisk marks primes):\n", limit);
        PrimeGenerator primeGen = new PrimeGenerator(1000, 100000);
        int prime1 = primeGen.nextPrime();
        for (int count = 1; ; ++count) {
            int prime2 = primeGen.nextPrime();
            int frobenius = prime1 * prime2 - prime1 - prime2;
            if (frobenius >= limit)
                break;
            System.out.printf("%6d%c%c", frobenius,
                    isPrime(frobenius) ? '*' : ' ',
                    count % 10 == 0 ? '\n' : ' ');
            prime1 = prime2;
        }
        System.out.println();
    }

    private static boolean isPrime(int n) {
        if (n < 2)
            return false;
        if (n % 2 == 0)
            return n == 2;
        if (n % 3 == 0)
            return n == 3;
        for (int p = 5; p * p <= n; p += 4) {
            if (n % p == 0)
                return false;
            p += 2;
            if (n % p == 0)
                return false;
        }
        return true;
    }
}
Task: Largest number divisible by its digits
C#: using System;

class Program {
    static int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

    
    static int lcmd(long x, int b) {
      int r = (int)(x % b), a; x /= b; while (x > 0) {
        r = (r * (a = (int)(x % b))) / gcd(r, a); x /= b; } return r; }

    static void Main(string[] args) {
        var sw = System.Diagnostics.Stopwatch.StartNew();
        long mx = 987654321; 
             mx = 98764321; 
             mx /= 10;     
        long skip = lcmd(mx, 10), i; bool nDup;
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString().ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k] || s[k] == '5') { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 10 = {0} in {1} μs\n", i,
          1000 * sw.Elapsed.TotalMilliseconds);
        sw.Restart();
        mx = 0xfedcba987654321;    
        skip = lcmd(mx >> 4, 16); 
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString("x").ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k]) { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 16 = {0} in {1} ms", i.ToString("x"),
          sw.Elapsed.TotalMilliseconds); } }

C++: #include <iostream>
#include <sstream>
#include <set>

bool checkDec(int num) {
    std::set<int> set;

    std::stringstream ss;
    ss << num;
    auto str = ss.str();

    for (int i = 0; i < str.size(); ++i) {
        char c = str[i];
        int d = c - '0';
        if (d == 0) return false;
        if (num % d != 0) return false;
        if (set.find(d) != set.end()) {
            return false;
        }
        set.insert(d);
    }

    return true;
}

int main() {
    for (int i = 98764321; i > 0; i--) {
        if (checkDec(i)) {
            std::cout << i << "\n";
            break;
        }
    }

    return 0;
}
Task: Largest number divisible by its digits
C++: #include <iostream>
#include <sstream>
#include <set>

bool checkDec(int num) {
    std::set<int> set;

    std::stringstream ss;
    ss << num;
    auto str = ss.str();

    for (int i = 0; i < str.size(); ++i) {
        char c = str[i];
        int d = c - '0';
        if (d == 0) return false;
        if (num % d != 0) return false;
        if (set.find(d) != set.end()) {
            return false;
        }
        set.insert(d);
    }

    return true;
}

int main() {
    for (int i = 98764321; i > 0; i--) {
        if (checkDec(i)) {
            std::cout << i << "\n";
            break;
        }
    }

    return 0;
}

Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

func divByAll(num int, digits []byte) bool {
    for _, digit := range digits {
        if num%int(digit-'0') != 0 {
            return false
        }
    }
    return true
}

func main() {
    magic := 9 * 8 * 7
    high := 9876432 / magic * magic
    for i := high; i >= magic; i -= magic {
        if i%10 == 0 {
            continue 
        }
        s := strconv.Itoa(i)
        if strings.ContainsAny(s, "05") {
            continue 
        }
        var set = make(map[byte]bool)
        var sd []byte 
        for _, b := range []byte(s) {
            if !set[b] {
                set[b] = true
                sd = append(sd, b)
            }
        }
        if len(sd) != len(s) {
            continue 
        }
        if divByAll(i, sd) {
            fmt.Println("Largest decimal number is", i)
            return
        }
    }
}
Task: Largest number divisible by its digits
C++: #include <iostream>
#include <sstream>
#include <set>

bool checkDec(int num) {
    std::set<int> set;

    std::stringstream ss;
    ss << num;
    auto str = ss.str();

    for (int i = 0; i < str.size(); ++i) {
        char c = str[i];
        int d = c - '0';
        if (d == 0) return false;
        if (num % d != 0) return false;
        if (set.find(d) != set.end()) {
            return false;
        }
        set.insert(d);
    }

    return true;
}

int main() {
    for (int i = 98764321; i > 0; i--) {
        if (checkDec(i)) {
            std::cout << i << "\n";
            break;
        }
    }

    return 0;
}

Java: public class LynchBell {
    
    static String s = "";
    
    public static void main(String args[]) {
        
        int i = 98764321;
        boolean isUnique = true;
        boolean canBeDivided = true;
        while (i>0) {
            s = String.valueOf(i);
            isUnique = uniqueDigits(i);
            if (isUnique) {
                
                canBeDivided = testNumber(i);
                if(canBeDivided) {
                    System.out.println("Number found: " + i);
                    i=0;
                }
            }
            i--;
        }
    }
    
    public static boolean uniqueDigits(int i) {
        
        for (int k = 0; k<s.length();k++) {
            for(int l=k+1; l<s.length();l++) {
                if(s.charAt(l)=='0' || s.charAt(l)=='5') {
                    
                    return false;
                }
                if(s.charAt(k) == s.charAt(l)) {
                    
                    return false;
                }
            }
        }
        return true;
    }
    
    public static boolean testNumber(int i) {
        
        int j = 0;
        boolean divisible = true;
        
        for (char ch: s.toCharArray()) {
            j = Character.getNumericValue(ch);
            divisible = ((i%j)==0);
            if (!divisible) {
                return false;
            }
        }       
        return true;
    }
}
Task: Largest number divisible by its digits
C++: #include <iostream>
#include <sstream>
#include <set>

bool checkDec(int num) {
    std::set<int> set;

    std::stringstream ss;
    ss << num;
    auto str = ss.str();

    for (int i = 0; i < str.size(); ++i) {
        char c = str[i];
        int d = c - '0';
        if (d == 0) return false;
        if (num % d != 0) return false;
        if (set.find(d) != set.end()) {
            return false;
        }
        set.insert(d);
    }

    return true;
}

int main() {
    for (int i = 98764321; i > 0; i--) {
        if (checkDec(i)) {
            std::cout << i << "\n";
            break;
        }
    }

    return 0;
}

Python: 

from itertools import (chain, permutations)
from functools import (reduce)
from math import (gcd)



def main():
    

    
    digits = [1, 2, 3, 4, 6, 7, 8, 9]

    
    lcmDigits = reduce(lcm, digits)

    
    
    sevenDigits = ((delete)(digits)(x) for x in [1, 4, 7])

    print(
        max(
            (
                intFromDigits(x) for x
                in concatMap(permutations)(sevenDigits)
            ),
            key=lambda n: n if 0 == n % lcmDigits else 0
        )
    )



def intFromDigits(xs):
    
    return reduce(lambda a, x: a * 10 + x, xs, 0)





def concatMap(f):
    
    def go(xs):
        return chain.from_iterable(map(f, xs))
    return go



def delete(xs):
    
    def go(x):
        ys = xs.copy()
        ys.remove(x)
        return ys
    return go



def lcm(x, y):
    
    return 0 if (0 == x or 0 == y) else abs(
        y * (x // gcd(x, y))
    )



if __name__ == '__main__':
    main()
Task: Largest number divisible by its digits
C#: using System;

class Program {
    static int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

    
    static int lcmd(long x, int b) {
      int r = (int)(x % b), a; x /= b; while (x > 0) {
        r = (r * (a = (int)(x % b))) / gcd(r, a); x /= b; } return r; }

    static void Main(string[] args) {
        var sw = System.Diagnostics.Stopwatch.StartNew();
        long mx = 987654321; 
             mx = 98764321; 
             mx /= 10;     
        long skip = lcmd(mx, 10), i; bool nDup;
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString().ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k] || s[k] == '5') { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 10 = {0} in {1} μs\n", i,
          1000 * sw.Elapsed.TotalMilliseconds);
        sw.Restart();
        mx = 0xfedcba987654321;    
        skip = lcmd(mx >> 4, 16); 
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString("x").ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k]) { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 16 = {0} in {1} ms", i.ToString("x"),
          sw.Elapsed.TotalMilliseconds); } }

Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

func divByAll(num int, digits []byte) bool {
    for _, digit := range digits {
        if num%int(digit-'0') != 0 {
            return false
        }
    }
    return true
}

func main() {
    magic := 9 * 8 * 7
    high := 9876432 / magic * magic
    for i := high; i >= magic; i -= magic {
        if i%10 == 0 {
            continue 
        }
        s := strconv.Itoa(i)
        if strings.ContainsAny(s, "05") {
            continue 
        }
        var set = make(map[byte]bool)
        var sd []byte 
        for _, b := range []byte(s) {
            if !set[b] {
                set[b] = true
                sd = append(sd, b)
            }
        }
        if len(sd) != len(s) {
            continue 
        }
        if divByAll(i, sd) {
            fmt.Println("Largest decimal number is", i)
            return
        }
    }
}
Task: Largest number divisible by its digits
C#: using System;

class Program {
    static int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

    
    static int lcmd(long x, int b) {
      int r = (int)(x % b), a; x /= b; while (x > 0) {
        r = (r * (a = (int)(x % b))) / gcd(r, a); x /= b; } return r; }

    static void Main(string[] args) {
        var sw = System.Diagnostics.Stopwatch.StartNew();
        long mx = 987654321; 
             mx = 98764321; 
             mx /= 10;     
        long skip = lcmd(mx, 10), i; bool nDup;
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString().ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k] || s[k] == '5') { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 10 = {0} in {1} μs\n", i,
          1000 * sw.Elapsed.TotalMilliseconds);
        sw.Restart();
        mx = 0xfedcba987654321;    
        skip = lcmd(mx >> 4, 16); 
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString("x").ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k]) { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 16 = {0} in {1} ms", i.ToString("x"),
          sw.Elapsed.TotalMilliseconds); } }

Java: public class LynchBell {
    
    static String s = "";
    
    public static void main(String args[]) {
        
        int i = 98764321;
        boolean isUnique = true;
        boolean canBeDivided = true;
        while (i>0) {
            s = String.valueOf(i);
            isUnique = uniqueDigits(i);
            if (isUnique) {
                
                canBeDivided = testNumber(i);
                if(canBeDivided) {
                    System.out.println("Number found: " + i);
                    i=0;
                }
            }
            i--;
        }
    }
    
    public static boolean uniqueDigits(int i) {
        
        for (int k = 0; k<s.length();k++) {
            for(int l=k+1; l<s.length();l++) {
                if(s.charAt(l)=='0' || s.charAt(l)=='5') {
                    
                    return false;
                }
                if(s.charAt(k) == s.charAt(l)) {
                    
                    return false;
                }
            }
        }
        return true;
    }
    
    public static boolean testNumber(int i) {
        
        int j = 0;
        boolean divisible = true;
        
        for (char ch: s.toCharArray()) {
            j = Character.getNumericValue(ch);
            divisible = ((i%j)==0);
            if (!divisible) {
                return false;
            }
        }       
        return true;
    }
}
Task: Largest number divisible by its digits
C#: using System;

class Program {
    static int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }

    
    static int lcmd(long x, int b) {
      int r = (int)(x % b), a; x /= b; while (x > 0) {
        r = (r * (a = (int)(x % b))) / gcd(r, a); x /= b; } return r; }

    static void Main(string[] args) {
        var sw = System.Diagnostics.Stopwatch.StartNew();
        long mx = 987654321; 
             mx = 98764321; 
             mx /= 10;     
        long skip = lcmd(mx, 10), i; bool nDup;
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString().ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k] || s[k] == '5') { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 10 = {0} in {1} μs\n", i,
          1000 * sw.Elapsed.TotalMilliseconds);
        sw.Restart();
        mx = 0xfedcba987654321;    
        skip = lcmd(mx >> 4, 16); 
        for (i = mx - mx % skip; ; i -= skip) {
            var s = i.ToString("x").ToCharArray(); Array.Sort(s);
            if (s[0] == '0') continue; 
            nDup = true; 
            for (int j = 0, k = 1; k < s.Length; j = k++)
                if (s[j] == s[k]) { nDup = false; break; }
            if (nDup) break; } sw.Stop(); 
        Console.Write("base 16 = {0} in {1} ms", i.ToString("x"),
          sw.Elapsed.TotalMilliseconds); } }

Python: 

from itertools import (chain, permutations)
from functools import (reduce)
from math import (gcd)



def main():
    

    
    digits = [1, 2, 3, 4, 6, 7, 8, 9]

    
    lcmDigits = reduce(lcm, digits)

    
    
    sevenDigits = ((delete)(digits)(x) for x in [1, 4, 7])

    print(
        max(
            (
                intFromDigits(x) for x
                in concatMap(permutations)(sevenDigits)
            ),
            key=lambda n: n if 0 == n % lcmDigits else 0
        )
    )



def intFromDigits(xs):
    
    return reduce(lambda a, x: a * 10 + x, xs, 0)





def concatMap(f):
    
    def go(xs):
        return chain.from_iterable(map(f, xs))
    return go



def delete(xs):
    
    def go(x):
        ys = xs.copy()
        ys.remove(x)
        return ys
    return go



def lcm(x, y):
    
    return 0 if (0 == x or 0 == y) else abs(
        y * (x // gcd(x, y))
    )



if __name__ == '__main__':
    main()
Task: Largest number divisible by its digits
Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

func divByAll(num int, digits []byte) bool {
    for _, digit := range digits {
        if num%int(digit-'0') != 0 {
            return false
        }
    }
    return true
}

func main() {
    magic := 9 * 8 * 7
    high := 9876432 / magic * magic
    for i := high; i >= magic; i -= magic {
        if i%10 == 0 {
            continue 
        }
        s := strconv.Itoa(i)
        if strings.ContainsAny(s, "05") {
            continue 
        }
        var set = make(map[byte]bool)
        var sd []byte 
        for _, b := range []byte(s) {
            if !set[b] {
                set[b] = true
                sd = append(sd, b)
            }
        }
        if len(sd) != len(s) {
            continue 
        }
        if divByAll(i, sd) {
            fmt.Println("Largest decimal number is", i)
            return
        }
    }
}

Java: public class LynchBell {
    
    static String s = "";
    
    public static void main(String args[]) {
        
        int i = 98764321;
        boolean isUnique = true;
        boolean canBeDivided = true;
        while (i>0) {
            s = String.valueOf(i);
            isUnique = uniqueDigits(i);
            if (isUnique) {
                
                canBeDivided = testNumber(i);
                if(canBeDivided) {
                    System.out.println("Number found: " + i);
                    i=0;
                }
            }
            i--;
        }
    }
    
    public static boolean uniqueDigits(int i) {
        
        for (int k = 0; k<s.length();k++) {
            for(int l=k+1; l<s.length();l++) {
                if(s.charAt(l)=='0' || s.charAt(l)=='5') {
                    
                    return false;
                }
                if(s.charAt(k) == s.charAt(l)) {
                    
                    return false;
                }
            }
        }
        return true;
    }
    
    public static boolean testNumber(int i) {
        
        int j = 0;
        boolean divisible = true;
        
        for (char ch: s.toCharArray()) {
            j = Character.getNumericValue(ch);
            divisible = ((i%j)==0);
            if (!divisible) {
                return false;
            }
        }       
        return true;
    }
}
Task: Largest number divisible by its digits
Java: public class LynchBell {
    
    static String s = "";
    
    public static void main(String args[]) {
        
        int i = 98764321;
        boolean isUnique = true;
        boolean canBeDivided = true;
        while (i>0) {
            s = String.valueOf(i);
            isUnique = uniqueDigits(i);
            if (isUnique) {
                
                canBeDivided = testNumber(i);
                if(canBeDivided) {
                    System.out.println("Number found: " + i);
                    i=0;
                }
            }
            i--;
        }
    }
    
    public static boolean uniqueDigits(int i) {
        
        for (int k = 0; k<s.length();k++) {
            for(int l=k+1; l<s.length();l++) {
                if(s.charAt(l)=='0' || s.charAt(l)=='5') {
                    
                    return false;
                }
                if(s.charAt(k) == s.charAt(l)) {
                    
                    return false;
                }
            }
        }
        return true;
    }
    
    public static boolean testNumber(int i) {
        
        int j = 0;
        boolean divisible = true;
        
        for (char ch: s.toCharArray()) {
            j = Character.getNumericValue(ch);
            divisible = ((i%j)==0);
            if (!divisible) {
                return false;
            }
        }       
        return true;
    }
}

Python: 

from itertools import (chain, permutations)
from functools import (reduce)
from math import (gcd)



def main():
    

    
    digits = [1, 2, 3, 4, 6, 7, 8, 9]

    
    lcmDigits = reduce(lcm, digits)

    
    
    sevenDigits = ((delete)(digits)(x) for x in [1, 4, 7])

    print(
        max(
            (
                intFromDigits(x) for x
                in concatMap(permutations)(sevenDigits)
            ),
            key=lambda n: n if 0 == n % lcmDigits else 0
        )
    )



def intFromDigits(xs):
    
    return reduce(lambda a, x: a * 10 + x, xs, 0)





def concatMap(f):
    
    def go(xs):
        return chain.from_iterable(map(f, xs))
    return go



def delete(xs):
    
    def go(x):
        ys = xs.copy()
        ys.remove(x)
        return ys
    return go



def lcm(x, y):
    
    return 0 if (0 == x or 0 == y) else abs(
        y * (x // gcd(x, y))
    )



if __name__ == '__main__':
    main()