WeixiangYan/CodeTransOcean huggingface dataset:
Task: Continued fraction




Go: package main

import "fmt"

type cfTerm struct {
    a, b int
}



type cf []cfTerm

func cfSqrt2(nTerms int) cf {
    f := make(cf, nTerms)
    for n := range f {
        f[n] = cfTerm{2, 1}
    }
    f[0].a = 1
    return f
}

func cfNap(nTerms int) cf {
    f := make(cf, nTerms)
    for n := range f {
        f[n] = cfTerm{n, n - 1}
    }
    f[0].a = 2
    f[1].b = 1
    return f
}

func cfPi(nTerms int) cf {
    f := make(cf, nTerms)
    for n := range f {
        g := 2*n - 1
        f[n] = cfTerm{6, g * g}
    }
    f[0].a = 3
    return f
}

func (f cf) real() (r float64) {
    for n := len(f) - 1; n > 0; n-- {
        r = float64(f[n].b) / (float64(f[n].a) + r)
    }
    return r + float64(f[0].a)
}

func main() {
    fmt.Println("sqrt2:", cfSqrt2(20).real())
    fmt.Println("nap:  ", cfNap(20).real())
    fmt.Println("pi:   ", cfPi(20).real())
}





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: 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