kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Continued fraction
Python: from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
 

def CF(a, b, t):
  terms = list(itertools.islice(zip(a, b), t))
  z = Fraction(1,1)
  for a, b in reversed(terms):
    z = a + b / z
  return z
 

def pRes(x, d):
  q, x = divmod(x, 1)
  res = str(q)
  res += "."
  for i in range(d):
    x *= 10
    q, x = divmod(x, 1)
    res += str(q)
  return res
 

def sqrt2_a():
  yield 1
  for x in itertools.repeat(2):
    yield x
 
def sqrt2_b():
  for x in itertools.repeat(1):
    yield x
 
cf = CF(sqrt2_a(), sqrt2_b(), 950)
print(pRes(cf, 200))

 
 

def Napier_a():
  yield 2
  for x in itertools.count(1):
    yield x
 
def Napier_b():
  yield 1
  for x in itertools.count(1):
    yield x
 
cf = CF(Napier_a(), Napier_b(), 950)
print(pRes(cf, 200))

 

def Pi_a():
  yield 3
  for x in itertools.repeat(6):
    yield x
 
def Pi_b():
  for x in itertools.count(1,2):
    yield x*x
 
cf = CF(Pi_a(), Pi_b(), 950)
print(pRes(cf, 10))


VB: Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
    Dim res As Double
    res = 0
    For n = steps To 1 Step -1
       res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
    Next n
    continued_fraction = Application.Run(rid_a, 0) + res
End Function
     
Function sqr2_a(n As Integer) As Integer
    sqr2_a = IIf(n = 0, 1, 2)
End Function

Function sqr2_b(n As Integer) As Integer
    sqr2_b = 1
End Function
 
Function nap_a(n As Integer) As Integer
    nap_a = IIf(n = 0, 2, n)
End Function

Function nap_b(n As Integer) As Integer
    nap_b = IIf(n = 1, 1, n - 1)
End Function
 
Function pi_a(n As Integer) As Integer
    pi_a = IIf(n = 0, 3, 6)
End Function

Function pi_b(n As Integer) As Long
    pi_b = IIf(n = 1, 1, (2 * n - 1) ^ 2)
End Function

Public Sub main()
    Debug.Print "Precision:", precision
    Debug.Print "Sqr(2):", continued_fraction(precision, "sqr2_a", "sqr2_b")
    Debug.Print "Napier:", continued_fraction(precision, "nap_a", "nap_b")
    Debug.Print "Pi:", continued_fraction(precision, "pi_a", "pi_b")
End Sub
Task: Permuted multiples
C: #include <stdio.h>
#include <stdbool.h>


int digit_set(int n) {
    static const int powers[] = {
        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
        100000000, 1000000000
    };
    
    int dset;
    for (dset = 0; n; n /= 10)
        dset += powers[n % 10];
    return dset;
}


bool is_permuted_multiple(int n) {
    int dset = digit_set(n);
    for (int mult = 2; mult <= 6; mult++)
        if (dset != digit_set(n * mult)) return false;
    return true;
}


int main() {
    int n;
    for (n = 123; !is_permuted_multiple(n); n++);
    for (int mult = 1; mult <= 6; mult++)
        printf("%d * n = %d\n", mult, n*mult);
    return 0;
}

C#: #include <array>
#include <iostream>

using digits = std::array<unsigned int, 10>;

digits get_digits(unsigned int n) {
    digits d = {};
    do {
        ++d[n % 10];
        n /= 10;
    } while (n > 0);
    return d;
}


bool same_digits(unsigned int n) {
    digits d = get_digits(n);
    for (unsigned int i = 0, m = n; i < 5; ++i) {
        m += n;
        if (get_digits(m) != d)
            return false;
    }
    return true;
}

int main() {
    for (unsigned int p = 100; ; p *= 10) {
        unsigned int max = (p * 10) / 6;
        for (unsigned int n = p + 2; n <= max; n += 3) {
            if (same_digits(n)) {
                std::cout << " n = " << n << '\n';
                for (unsigned int i = 2; i <= 6; ++i)
                    std::cout << i << "n = " << n * i << '\n';
                return 0;
            }
        }
    }
}
Task: Permuted multiples
C: #include <stdio.h>
#include <stdbool.h>


int digit_set(int n) {
    static const int powers[] = {
        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
        100000000, 1000000000
    };
    
    int dset;
    for (dset = 0; n; n /= 10)
        dset += powers[n % 10];
    return dset;
}


bool is_permuted_multiple(int n) {
    int dset = digit_set(n);
    for (int mult = 2; mult <= 6; mult++)
        if (dset != digit_set(n * mult)) return false;
    return true;
}


int main() {
    int n;
    for (n = 123; !is_permuted_multiple(n); n++);
    for (int mult = 1; mult <= 6; mult++)
        printf("%d * n = %d\n", mult, n*mult);
    return 0;
}

C++: #include <array>
#include <iostream>

using digits = std::array<unsigned int, 10>;

digits get_digits(unsigned int n) {
    digits d = {};
    do {
        ++d[n % 10];
        n /= 10;
    } while (n > 0);
    return d;
}


bool same_digits(unsigned int n) {
    digits d = get_digits(n);
    for (unsigned int i = 0, m = n; i < 5; ++i) {
        m += n;
        if (get_digits(m) != d)
            return false;
    }
    return true;
}

int main() {
    for (unsigned int p = 100; ; p *= 10) {
        unsigned int max = (p * 10) / 6;
        for (unsigned int n = p + 2; n <= max; n += 3) {
            if (same_digits(n)) {
                std::cout << " n = " << n << '\n';
                for (unsigned int i = 2; i <= 6; ++i)
                    std::cout << i << "n = " << n * i << '\n';
                return 0;
            }
        }
    }
}
Task: Permuted multiples
C: #include <stdio.h>
#include <stdbool.h>


int digit_set(int n) {
    static const int powers[] = {
        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
        100000000, 1000000000
    };
    
    int dset;
    for (dset = 0; n; n /= 10)
        dset += powers[n % 10];
    return dset;
}


bool is_permuted_multiple(int n) {
    int dset = digit_set(n);
    for (int mult = 2; mult <= 6; mult++)
        if (dset != digit_set(n * mult)) return false;
    return true;
}


int main() {
    int n;
    for (n = 123; !is_permuted_multiple(n); n++);
    for (int mult = 1; mult <= 6; mult++)
        printf("%d * n = %d\n", mult, n*mult);
    return 0;
}

Go: package main

import (
    "fmt"
    "rcu"
    "sort"
)


func areSame(l1, l2 []int) bool {
    if len(l1) != len(l2) {
        return false
    }
    sort.Ints(l2)
    for i := 0; i < len(l1); i++ {
        if l1[i] != l2[i] {
            return false
        }
    }
    return true
}

func main() {
    i := 100 
    nextPow := 1000
    for {
        digits := rcu.Digits(i, 10)
        if digits[0] != 1 {
            i = nextPow
            nextPow *= 10
            continue
        }
        sort.Ints(digits)
        allSame := true
        for j := 2; j <= 6; j++ {
            digits2 := rcu.Digits(i*j, 10)
            if !areSame(digits, digits2) {
                allSame = false
                break
            }
        }
        if allSame {
            fmt.Println("The smallest positive integer n for which the following")
            fmt.Println("multiples contain exactly the same digits is:")
            fmt.Println("    n =", i)
            for k := 2; k <= 6; k++ {
                fmt.Printf("%d x n = %d\n", k, k*i)
            }
            return
        }
        i = i + 1
    }
}
Task: Permuted multiples
C: #include <stdio.h>
#include <stdbool.h>


int digit_set(int n) {
    static const int powers[] = {
        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
        100000000, 1000000000
    };
    
    int dset;
    for (dset = 0; n; n /= 10)
        dset += powers[n % 10];
    return dset;
}


bool is_permuted_multiple(int n) {
    int dset = digit_set(n);
    for (int mult = 2; mult <= 6; mult++)
        if (dset != digit_set(n * mult)) return false;
    return true;
}


int main() {
    int n;
    for (n = 123; !is_permuted_multiple(n); n++);
    for (int mult = 1; mult <= 6; mult++)
        printf("%d * n = %d\n", mult, n*mult);
    return 0;
}

Java: import java.util.*;

public class PermutedMultiples {
    public static void main(String[] args) {
        for (int p = 100; ; p *= 10) {
            int max = (p * 10) / 6;
            for (int n = p + 2; n <= max; n += 3) {
                if (sameDigits(n)) {
                    System.out.printf(" n = %d\n", n);
                    for (int i = 2; i <= 6; ++i)
                        System.out.printf("%dn = %d\n", i, n * i);
                    return;
                }
            }
        }
    }

    
    private static boolean sameDigits(int n) {
        int[] digits = getDigits(n);
        for (int i = 0, m = n; i < 5; ++i) {
            m += n;
            if (!Arrays.equals(getDigits(m), digits))
                return false;
        }
        return true;
    }

    private static int[] getDigits(int n) {
        int[] digits = new int[10];
        do {
            ++digits[n % 10];
            n /= 10;
        } while (n > 0);
        return digits;
    }
}
Task: Permuted multiples
C++: #include <array>
#include <iostream>

using digits = std::array<unsigned int, 10>;

digits get_digits(unsigned int n) {
    digits d = {};
    do {
        ++d[n % 10];
        n /= 10;
    } while (n > 0);
    return d;
}


bool same_digits(unsigned int n) {
    digits d = get_digits(n);
    for (unsigned int i = 0, m = n; i < 5; ++i) {
        m += n;
        if (get_digits(m) != d)
            return false;
    }
    return true;
}

int main() {
    for (unsigned int p = 100; ; p *= 10) {
        unsigned int max = (p * 10) / 6;
        for (unsigned int n = p + 2; n <= max; n += 3) {
            if (same_digits(n)) {
                std::cout << " n = " << n << '\n';
                for (unsigned int i = 2; i <= 6; ++i)
                    std::cout << i << "n = " << n * i << '\n';
                return 0;
            }
        }
    }
}

Go: package main

import (
    "fmt"
    "rcu"
    "sort"
)


func areSame(l1, l2 []int) bool {
    if len(l1) != len(l2) {
        return false
    }
    sort.Ints(l2)
    for i := 0; i < len(l1); i++ {
        if l1[i] != l2[i] {
            return false
        }
    }
    return true
}

func main() {
    i := 100 
    nextPow := 1000
    for {
        digits := rcu.Digits(i, 10)
        if digits[0] != 1 {
            i = nextPow
            nextPow *= 10
            continue
        }
        sort.Ints(digits)
        allSame := true
        for j := 2; j <= 6; j++ {
            digits2 := rcu.Digits(i*j, 10)
            if !areSame(digits, digits2) {
                allSame = false
                break
            }
        }
        if allSame {
            fmt.Println("The smallest positive integer n for which the following")
            fmt.Println("multiples contain exactly the same digits is:")
            fmt.Println("    n =", i)
            for k := 2; k <= 6; k++ {
                fmt.Printf("%d x n = %d\n", k, k*i)
            }
            return
        }
        i = i + 1
    }
}
Task: Permuted multiples
C++: #include <array>
#include <iostream>

using digits = std::array<unsigned int, 10>;

digits get_digits(unsigned int n) {
    digits d = {};
    do {
        ++d[n % 10];
        n /= 10;
    } while (n > 0);
    return d;
}


bool same_digits(unsigned int n) {
    digits d = get_digits(n);
    for (unsigned int i = 0, m = n; i < 5; ++i) {
        m += n;
        if (get_digits(m) != d)
            return false;
    }
    return true;
}

int main() {
    for (unsigned int p = 100; ; p *= 10) {
        unsigned int max = (p * 10) / 6;
        for (unsigned int n = p + 2; n <= max; n += 3) {
            if (same_digits(n)) {
                std::cout << " n = " << n << '\n';
                for (unsigned int i = 2; i <= 6; ++i)
                    std::cout << i << "n = " << n * i << '\n';
                return 0;
            }
        }
    }
}

Java: import java.util.*;

public class PermutedMultiples {
    public static void main(String[] args) {
        for (int p = 100; ; p *= 10) {
            int max = (p * 10) / 6;
            for (int n = p + 2; n <= max; n += 3) {
                if (sameDigits(n)) {
                    System.out.printf(" n = %d\n", n);
                    for (int i = 2; i <= 6; ++i)
                        System.out.printf("%dn = %d\n", i, n * i);
                    return;
                }
            }
        }
    }

    
    private static boolean sameDigits(int n) {
        int[] digits = getDigits(n);
        for (int i = 0, m = n; i < 5; ++i) {
            m += n;
            if (!Arrays.equals(getDigits(m), digits))
                return false;
        }
        return true;
    }

    private static int[] getDigits(int n) {
        int[] digits = new int[10];
        do {
            ++digits[n % 10];
            n /= 10;
        } while (n > 0);
        return digits;
    }
}
Task: Permuted multiples
Go: package main

import (
    "fmt"
    "rcu"
    "sort"
)


func areSame(l1, l2 []int) bool {
    if len(l1) != len(l2) {
        return false
    }
    sort.Ints(l2)
    for i := 0; i < len(l1); i++ {
        if l1[i] != l2[i] {
            return false
        }
    }
    return true
}

func main() {
    i := 100 
    nextPow := 1000
    for {
        digits := rcu.Digits(i, 10)
        if digits[0] != 1 {
            i = nextPow
            nextPow *= 10
            continue
        }
        sort.Ints(digits)
        allSame := true
        for j := 2; j <= 6; j++ {
            digits2 := rcu.Digits(i*j, 10)
            if !areSame(digits, digits2) {
                allSame = false
                break
            }
        }
        if allSame {
            fmt.Println("The smallest positive integer n for which the following")
            fmt.Println("multiples contain exactly the same digits is:")
            fmt.Println("    n =", i)
            for k := 2; k <= 6; k++ {
                fmt.Printf("%d x n = %d\n", k, k*i)
            }
            return
        }
        i = i + 1
    }
}

Java: import java.util.*;

public class PermutedMultiples {
    public static void main(String[] args) {
        for (int p = 100; ; p *= 10) {
            int max = (p * 10) / 6;
            for (int n = p + 2; n <= max; n += 3) {
                if (sameDigits(n)) {
                    System.out.printf(" n = %d\n", n);
                    for (int i = 2; i <= 6; ++i)
                        System.out.printf("%dn = %d\n", i, n * i);
                    return;
                }
            }
        }
    }

    
    private static boolean sameDigits(int n) {
        int[] digits = getDigits(n);
        for (int i = 0, m = n; i < 5; ++i) {
            m += n;
            if (!Arrays.equals(getDigits(m), digits))
                return false;
        }
        return true;
    }

    private static int[] getDigits(int n) {
        int[] digits = new int[10];
        do {
            ++digits[n % 10];
            n /= 10;
        } while (n > 0);
        return digits;
    }
}
Task: Length of an arc between two angles
C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}

C#: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}
Task: Length of an arc between two angles
C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}

Go: package main

import (
    "fmt"
    "math"
)

func arcLength(radius, angle1, angle2 float64) float64 {
    return (360 - math.Abs(angle2-angle1)) * math.Pi * radius / 180
}

func main() {
    fmt.Println(arcLength(10, 10, 120))
}
Task: Length of an arc between two angles
C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}

Java: public static double arcLength(double r, double a1, double a2){
    return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r;
}
Task: Length of an arc between two angles
C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}

Python: import math

def arc_length(r, angleA, angleB):
    return (360.0 - abs(angleB - angleA)) * math.pi * r / 180.0
Task: Length of an arc between two angles
C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}

Go: package main

import (
    "fmt"
    "math"
)

func arcLength(radius, angle1, angle2 float64) float64 {
    return (360 - math.Abs(angle2-angle1)) * math.Pi * radius / 180
}

func main() {
    fmt.Println(arcLength(10, 10, 120))
}
Task: Length of an arc between two angles
C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}

Java: public static double arcLength(double r, double a1, double a2){
    return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r;
}
Task: Length of an arc between two angles
Go: package main

import (
    "fmt"
    "math"
)

func arcLength(radius, angle1, angle2 float64) float64 {
    return (360 - math.Abs(angle2-angle1)) * math.Pi * radius / 180
}

func main() {
    fmt.Println(arcLength(10, 10, 120))
}

Java: public static double arcLength(double r, double a1, double a2){
    return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r;
}
Task: Length of an arc between two angles
Java: public static double arcLength(double r, double a1, double a2){
    return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r;
}

Python: import math

def arc_length(r, angleA, angleB):
    return (360.0 - abs(angleB - angleA)) * math.pi * r / 180.0
Task: Length of an arc between two angles
C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}

C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}
Task: Length of an arc between two angles
Go: package main

import (
    "fmt"
    "math"
)

func arcLength(radius, angle1, angle2 float64) float64 {
    return (360 - math.Abs(angle2-angle1)) * math.Pi * radius / 180
}

func main() {
    fmt.Println(arcLength(10, 10, 120))
}

Python: import math

def arc_length(r, angleA, angleB):
    return (360.0 - abs(angleB - angleA)) * math.pi * r / 180.0
Task: Length of an arc between two angles
C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}

Python: import math

def arc_length(r, angleA, angleB):
    return (360.0 - abs(angleB - angleA)) * math.pi * r / 180.0
Task: World Cup group stage
C: #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int compare(const void *a, const void *b) {
    int int_a = *((int *)a);
    int int_b = *((int *)b);
    return (int_a > int_b) - (int_a < int_b);
}

char results[7];
bool next_result() {
    char *ptr = results + 5;
    int num = 0;
    size_t i;

    
    if (strcmp(results, "222222") == 0) {
        return false;
    }

    
    for (i = 0; results[i] != 0; i++) {
        int d = results[i] - '0';
        num = 3 * num + d;
    }

    
    num++;

    
    while (num > 0) {
        int rem = num % 3;
        num /= 3;
        *ptr-- = rem + '0';
    }
    
    while (ptr > results) {
        *ptr-- = '0';
    }

    return true;
}

char *games[6] = { "12", "13", "14", "23", "24", "34" };
char *places[4] = { "1st", "2nd", "3rd", "4th" };
int main() {
    int points[4][10];
    size_t i, j;

    strcpy(results, "000000");
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 10; j++) {
            points[i][j] = 0;
        }
    }

    do {
        int records[] = { 0, 0, 0, 0 };

        for (i = 0; i < 6; i++) {
            switch (results[i]) {
            case '2':
                records[games[i][0] - '1'] += 3;
                break;
            case '1':
                records[games[i][0] - '1']++;
                records[games[i][1] - '1']++;
                break;
            case '0':
                records[games[i][1] - '1'] += 3;
                break;
            default:
                break;
            }
        }

        qsort(records, 4, sizeof(int), compare);
        for (i = 0; i < 4; i++) {
            points[i][records[i]]++;
        }
    } while (next_result());

    printf("POINTS       0    1    2    3    4    5    6    7    8    9\n");
    printf("-----------------------------------------------------------\n");
    for (i = 0; i < 4; i++) {
        printf("%s place", places[i]);
        for (j = 0; j < 10; j++) {
            printf("%5d", points[3 - i][j]);
        }
        printf("\n");
    }

    return 0;
}

Python: from itertools import product, combinations, izip

scoring = [0, 1, 3]
histo = [[0] * 10 for _ in xrange(4)]

for results in product(range(3), repeat=6):
    s = [0] * 4
    for r, g in izip(results, combinations(range(4), 2)):
        s[g[0]] += scoring[r]
        s[g[1]] += scoring[2 - r]

    for h, v in izip(histo, sorted(s)):
        h[v] += 1

for x in reversed(histo):
    print x