WeixiangYan/CodeTransOcean huggingface dataset:
Task: Fusc sequence

C: #include<limits.h>
#include<stdio.h>

int fusc(int n){
        if(n==0||n==1)
                return n;
        else if(n%2==0)
                return fusc(n/2);
        else
                return fusc((n-1)/2) + fusc((n+1)/2);
}

int numLen(int n){
        int sum = 1;

        while(n>9){
                n = n/10;
                sum++;
        }

        return sum;
}

void printLargeFuscs(int limit){
        int i,f,len,maxLen = 1;

        printf("\n\nPrinting all largest Fusc numbers upto %d \nIndex-------Value",limit);

        for(i=0;i<=limit;i++){
                f = fusc(i);
                len = numLen(f);

                if(len>maxLen){
                        maxLen = len;
                        printf("\n%5d%12d",i,f);
                }
        }
}


int main()
{
        int i;

        printf("Index-------Value");
        for(i=0;i<61;i++)
                printf("\n%5d%12d",i,fusc(i));
        printLargeFuscs(INT_MAX);
        return 0;
}


C++: #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

const int n = 61;
std::vector<int> l{ 0, 1 };

int fusc(int n) {
    if (n < l.size()) return l[n];
    int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
    l.push_back(f);
    return f;
}

int main() {
    bool lst = true;
    int w = -1;
    int c = 0;
    int t;
    std::string res;
    std::cout << "First " << n << " numbers in the fusc sequence:\n";
    for (int i = 0; i < INT32_MAX; i++) {
        int f = fusc(i);
        if (lst) {
            if (i < 61) {
                std::cout << f << ' ';
            } else {
                lst = false;
                std::cout << "\nPoints in the sequence where an item has more digits than any previous items:\n";
                std::cout << std::setw(11) << "Index\\" << "  " << std::left << std::setw(9) << "/Value\n";
                std::cout << res << '\n';
                res = "";
            }
        }
        std::stringstream ss;
        ss << f;
        t = ss.str().length();
        ss.str("");
        ss.clear();
        if (t > w) {
            w = t;
            res += (res == "" ? "" : "\n");
            ss << std::setw(11) << i << "  " << std::left << std::setw(9) << f;
            res += ss.str();
            if (!lst) {
                std::cout << res << '\n';
                res = "";
            }
            if (++c > 5) {
                break;
            }
        }
    }
    return 0;
}
Task: Fusc sequence

C: #include<limits.h>
#include<stdio.h>

int fusc(int n){
        if(n==0||n==1)
                return n;
        else if(n%2==0)
                return fusc(n/2);
        else
                return fusc((n-1)/2) + fusc((n+1)/2);
}

int numLen(int n){
        int sum = 1;

        while(n>9){
                n = n/10;
                sum++;
        }

        return sum;
}

void printLargeFuscs(int limit){
        int i,f,len,maxLen = 1;

        printf("\n\nPrinting all largest Fusc numbers upto %d \nIndex-------Value",limit);

        for(i=0;i<=limit;i++){
                f = fusc(i);
                len = numLen(f);

                if(len>maxLen){
                        maxLen = len;
                        printf("\n%5d%12d",i,f);
                }
        }
}


int main()
{
        int i;

        printf("Index-------Value");
        for(i=0;i<61;i++)
                printf("\n%5d%12d",i,fusc(i));
        printLargeFuscs(INT_MAX);
        return 0;
}




Go: package main

import (
    "fmt"
    "strconv"
)

func fusc(n int) []int {
    if n <= 0 {
        return []int{}
    }
    if n == 1 {
        return []int{0}
    }    
    res := make([]int, n)
    res[0] = 0
    res[1] = 1
    for i := 2; i < n; i++ {
        if i%2 == 0 {
            res[i] = res[i/2]
        } else {
            res[i] = res[(i-1)/2] + res[(i+1)/2]
        }
    }
    return res
}

func fuscMaxLen(n int) [][2]int {
    maxLen := -1
    maxFusc := -1
    f := fusc(n)
    var res [][2]int
    for i := 0; i < n; i++ {
        if f[i] <= maxFusc {
            continue 
        }
        maxFusc = f[i]
        le := len(strconv.Itoa(f[i]))
        if le > maxLen {
            res = append(res, [2]int{i, f[i]})
            maxLen = le
        }
    }
    return res
}

func commatize(n int) string {
    s := fmt.Sprintf("%d", n)
    if n < 0 {
        s = s[1:]
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if n >= 0 {
        return s
    }
    return "-" + s
}

func main() {
    fmt.Println("The first 61 fusc numbers are:")
    fmt.Println(fusc(61))
    fmt.Println("\nThe fusc numbers whose length > any previous fusc number length are:")
    res := fuscMaxLen(20000000)  
    for i := 0; i < len(res); i++ {
        fmt.Printf("%7s (index %10s)\n", commatize(res[i][1]), commatize(res[i][0]))
    }
}
Task: Fusc sequence

C: #include<limits.h>
#include<stdio.h>

int fusc(int n){
        if(n==0||n==1)
                return n;
        else if(n%2==0)
                return fusc(n/2);
        else
                return fusc((n-1)/2) + fusc((n+1)/2);
}

int numLen(int n){
        int sum = 1;

        while(n>9){
                n = n/10;
                sum++;
        }

        return sum;
}

void printLargeFuscs(int limit){
        int i,f,len,maxLen = 1;

        printf("\n\nPrinting all largest Fusc numbers upto %d \nIndex-------Value",limit);

        for(i=0;i<=limit;i++){
                f = fusc(i);
                len = numLen(f);

                if(len>maxLen){
                        maxLen = len;
                        printf("\n%5d%12d",i,f);
                }
        }
}


int main()
{
        int i;

        printf("Index-------Value");
        for(i=0;i<61;i++)
                printf("\n%5d%12d",i,fusc(i));
        printLargeFuscs(INT_MAX);
        return 0;
}





Java: public class FuscSequence {

    public static void main(String[] args) {
        System.out.println("Show the first 61 fusc numbers (starting at zero) in a horizontal format");
        for ( int n = 0 ; n < 61 ; n++ ) {
            System.out.printf("%,d ", fusc[n]);
        }
        
        System.out.printf("%n%nShow the fusc number (and its index) whose length is greater than any previous fusc number length.%n");
        int start = 0;
        for (int i = 0 ; i <= 5 ; i++ ) {
            int val = i != 0 ? (int) Math.pow(10, i) : -1;
            for ( int j = start ; j < FUSC_MAX ; j++ ) {
                if ( fusc[j] > val ) {
                    System.out.printf("fusc[%,d] = %,d%n", j, fusc[j] );
                    start = j;
                    break;
                }
            }
        }
    }
    
    private static final int FUSC_MAX = 30000000;
    private static int[] fusc = new int[FUSC_MAX];

    static {
        fusc[0] = 0;
        fusc[1] = 1;
        for ( int n = 2 ; n < FUSC_MAX ; n++ ) {
            fusc[n] = (n % 2 == 0 ? fusc[n/2] : fusc[(n-1)/2] + fusc[(n+1)/2]);
        }
    }
}
Task: Fusc sequence

C: #include<limits.h>
#include<stdio.h>

int fusc(int n){
        if(n==0||n==1)
                return n;
        else if(n%2==0)
                return fusc(n/2);
        else
                return fusc((n-1)/2) + fusc((n+1)/2);
}

int numLen(int n){
        int sum = 1;

        while(n>9){
                n = n/10;
                sum++;
        }

        return sum;
}

void printLargeFuscs(int limit){
        int i,f,len,maxLen = 1;

        printf("\n\nPrinting all largest Fusc numbers upto %d \nIndex-------Value",limit);

        for(i=0;i<=limit;i++){
                f = fusc(i);
                len = numLen(f);

                if(len>maxLen){
                        maxLen = len;
                        printf("\n%5d%12d",i,f);
                }
        }
}


int main()
{
        int i;

        printf("Index-------Value");
        for(i=0;i<61;i++)
                printf("\n%5d%12d",i,fusc(i));
        printLargeFuscs(INT_MAX);
        return 0;
}







Python: from collections import deque
from itertools import islice, count


def fusc():
    q = deque([1])
    yield 0
    yield 1

    while True:
        x = q.popleft()
        q.append(x)
        yield x

        x += q[0]
        q.append(x)
        yield x


def longest_fusc():
    sofar = 0
    for i, f in zip(count(), fusc()):
        if f >= sofar:
            yield(i, f)
            sofar = 10 * sofar or 10


print('First 61:')
print(list(islice(fusc(), 61)))

print('\nLength records:')
for i, f in islice(longest_fusc(), 6):
    print(f'fusc({i}) = {f}')
Task: Fusc sequence

C: #include<limits.h>
#include<stdio.h>

int fusc(int n){
        if(n==0||n==1)
                return n;
        else if(n%2==0)
                return fusc(n/2);
        else
                return fusc((n-1)/2) + fusc((n+1)/2);
}

int numLen(int n){
        int sum = 1;

        while(n>9){
                n = n/10;
                sum++;
        }

        return sum;
}

void printLargeFuscs(int limit){
        int i,f,len,maxLen = 1;

        printf("\n\nPrinting all largest Fusc numbers upto %d \nIndex-------Value",limit);

        for(i=0;i<=limit;i++){
                f = fusc(i);
                len = numLen(f);

                if(len>maxLen){
                        maxLen = len;
                        printf("\n%5d%12d",i,f);
                }
        }
}


int main()
{
        int i;

        printf("Index-------Value");
        for(i=0;i<61;i++)
                printf("\n%5d%12d",i,fusc(i));
        printLargeFuscs(INT_MAX);
        return 0;
}








VB: Module Module1

    Dim n As Integer = 61, l As List(Of Integer) = {0, 1}.ToList

    Function fusc(n As Integer) As Integer
        If n < l.Count Then Return l(n)
        fusc = If((n And 1) = 0, l(n >> 1), l((n - 1) >> 1) + l((n + 1) >> 1))
        l.Add(fusc)
    End Function

    Sub Main(args As String())
        Dim lst As Boolean = True, w As Integer = -1, c As Integer = 0,
            fs As String = "{0,11:n0}  {1,-9:n0}", res As String = ""
        Console.WriteLine("First {0} numbers in the fusc sequence:", n)
        For i As Integer = 0 To Integer.MaxValue
            Dim f As Integer = fusc(i)
            If lst Then
                If i < 61 Then
                    Console.Write("{0} ", f)
                Else
                    lst = False
                    Console.WriteLine()
                    Console.WriteLine("Points in the sequence where an item has more digits than any previous items:")
                    Console.WriteLine(fs, "Index\", "/Value") : Console.WriteLine(res) : res = ""
                End If
            End If
            Dim t As Integer = f.ToString.Length
            If t > w Then
                w = t
                res &= If(res = "", "", vbLf) & String.Format(fs, i, f)
                If Not lst Then Console.WriteLine(res) : res = ""
                c += 1 : If c > 5 Then Exit For
            End If
        Next : l.Clear()
    End Sub
End Module
Task: Fusc sequence


C++: #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

const int n = 61;
std::vector<int> l{ 0, 1 };

int fusc(int n) {
    if (n < l.size()) return l[n];
    int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
    l.push_back(f);
    return f;
}

int main() {
    bool lst = true;
    int w = -1;
    int c = 0;
    int t;
    std::string res;
    std::cout << "First " << n << " numbers in the fusc sequence:\n";
    for (int i = 0; i < INT32_MAX; i++) {
        int f = fusc(i);
        if (lst) {
            if (i < 61) {
                std::cout << f << ' ';
            } else {
                lst = false;
                std::cout << "\nPoints in the sequence where an item has more digits than any previous items:\n";
                std::cout << std::setw(11) << "Index\\" << "  " << std::left << std::setw(9) << "/Value\n";
                std::cout << res << '\n';
                res = "";
            }
        }
        std::stringstream ss;
        ss << f;
        t = ss.str().length();
        ss.str("");
        ss.clear();
        if (t > w) {
            w = t;
            res += (res == "" ? "" : "\n");
            ss << std::setw(11) << i << "  " << std::left << std::setw(9) << f;
            res += ss.str();
            if (!lst) {
                std::cout << res << '\n';
                res = "";
            }
            if (++c > 5) {
                break;
            }
        }
    }
    return 0;
}


C#: using System;
using System.Collections.Generic;

static class program
{
    static int n = 61;
    static List<int> l = new List<int>() { 0, 1 };

    static int fusc(int n)
    {
        if (n < l.Count) return l[n];
        int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
        l.Add(f); return f;
    }

    static void Main(string[] args)
    {
        bool lst = true; int w = -1, c = 0, t;
        string fs = "{0,11:n0}  {1,-9:n0}", res = "";
        Console.WriteLine("First {0} numbers in the fusc sequence:", n);
        for (int i = 0; i < int.MaxValue; i++)
        {
            int f = fusc(i); if (lst)
            {
                if (i < 61) Console.Write("{0} ", f);
                else
                {
                    lst = false;
                    Console.WriteLine();
                    Console.WriteLine("Points in the sequence where an item has more digits than any previous items:");
                    Console.WriteLine(fs, "Index\\", "/Value"); Console.WriteLine(res); res = "";
                }
            }
            if ((t = f.ToString().Length) > w)
            {
                w = t; res += (res == "" ? "" : "\n") + string.Format(fs, i, f);
                if (!lst) { Console.WriteLine(res); res = ""; } if (++c > 5) break;
            }
        }
        l.Clear();
    }
}
Task: Fusc sequence


C++: #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

const int n = 61;
std::vector<int> l{ 0, 1 };

int fusc(int n) {
    if (n < l.size()) return l[n];
    int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
    l.push_back(f);
    return f;
}

int main() {
    bool lst = true;
    int w = -1;
    int c = 0;
    int t;
    std::string res;
    std::cout << "First " << n << " numbers in the fusc sequence:\n";
    for (int i = 0; i < INT32_MAX; i++) {
        int f = fusc(i);
        if (lst) {
            if (i < 61) {
                std::cout << f << ' ';
            } else {
                lst = false;
                std::cout << "\nPoints in the sequence where an item has more digits than any previous items:\n";
                std::cout << std::setw(11) << "Index\\" << "  " << std::left << std::setw(9) << "/Value\n";
                std::cout << res << '\n';
                res = "";
            }
        }
        std::stringstream ss;
        ss << f;
        t = ss.str().length();
        ss.str("");
        ss.clear();
        if (t > w) {
            w = t;
            res += (res == "" ? "" : "\n");
            ss << std::setw(11) << i << "  " << std::left << std::setw(9) << f;
            res += ss.str();
            if (!lst) {
                std::cout << res << '\n';
                res = "";
            }
            if (++c > 5) {
                break;
            }
        }
    }
    return 0;
}



Go: package main

import (
    "fmt"
    "strconv"
)

func fusc(n int) []int {
    if n <= 0 {
        return []int{}
    }
    if n == 1 {
        return []int{0}
    }    
    res := make([]int, n)
    res[0] = 0
    res[1] = 1
    for i := 2; i < n; i++ {
        if i%2 == 0 {
            res[i] = res[i/2]
        } else {
            res[i] = res[(i-1)/2] + res[(i+1)/2]
        }
    }
    return res
}

func fuscMaxLen(n int) [][2]int {
    maxLen := -1
    maxFusc := -1
    f := fusc(n)
    var res [][2]int
    for i := 0; i < n; i++ {
        if f[i] <= maxFusc {
            continue 
        }
        maxFusc = f[i]
        le := len(strconv.Itoa(f[i]))
        if le > maxLen {
            res = append(res, [2]int{i, f[i]})
            maxLen = le
        }
    }
    return res
}

func commatize(n int) string {
    s := fmt.Sprintf("%d", n)
    if n < 0 {
        s = s[1:]
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if n >= 0 {
        return s
    }
    return "-" + s
}

func main() {
    fmt.Println("The first 61 fusc numbers are:")
    fmt.Println(fusc(61))
    fmt.Println("\nThe fusc numbers whose length > any previous fusc number length are:")
    res := fuscMaxLen(20000000)  
    for i := 0; i < len(res); i++ {
        fmt.Printf("%7s (index %10s)\n", commatize(res[i][1]), commatize(res[i][0]))
    }
}
Task: Fusc sequence


C++: #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

const int n = 61;
std::vector<int> l{ 0, 1 };

int fusc(int n) {
    if (n < l.size()) return l[n];
    int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
    l.push_back(f);
    return f;
}

int main() {
    bool lst = true;
    int w = -1;
    int c = 0;
    int t;
    std::string res;
    std::cout << "First " << n << " numbers in the fusc sequence:\n";
    for (int i = 0; i < INT32_MAX; i++) {
        int f = fusc(i);
        if (lst) {
            if (i < 61) {
                std::cout << f << ' ';
            } else {
                lst = false;
                std::cout << "\nPoints in the sequence where an item has more digits than any previous items:\n";
                std::cout << std::setw(11) << "Index\\" << "  " << std::left << std::setw(9) << "/Value\n";
                std::cout << res << '\n';
                res = "";
            }
        }
        std::stringstream ss;
        ss << f;
        t = ss.str().length();
        ss.str("");
        ss.clear();
        if (t > w) {
            w = t;
            res += (res == "" ? "" : "\n");
            ss << std::setw(11) << i << "  " << std::left << std::setw(9) << f;
            res += ss.str();
            if (!lst) {
                std::cout << res << '\n';
                res = "";
            }
            if (++c > 5) {
                break;
            }
        }
    }
    return 0;
}




Java: public class FuscSequence {

    public static void main(String[] args) {
        System.out.println("Show the first 61 fusc numbers (starting at zero) in a horizontal format");
        for ( int n = 0 ; n < 61 ; n++ ) {
            System.out.printf("%,d ", fusc[n]);
        }
        
        System.out.printf("%n%nShow the fusc number (and its index) whose length is greater than any previous fusc number length.%n");
        int start = 0;
        for (int i = 0 ; i <= 5 ; i++ ) {
            int val = i != 0 ? (int) Math.pow(10, i) : -1;
            for ( int j = start ; j < FUSC_MAX ; j++ ) {
                if ( fusc[j] > val ) {
                    System.out.printf("fusc[%,d] = %,d%n", j, fusc[j] );
                    start = j;
                    break;
                }
            }
        }
    }
    
    private static final int FUSC_MAX = 30000000;
    private static int[] fusc = new int[FUSC_MAX];

    static {
        fusc[0] = 0;
        fusc[1] = 1;
        for ( int n = 2 ; n < FUSC_MAX ; n++ ) {
            fusc[n] = (n % 2 == 0 ? fusc[n/2] : fusc[(n-1)/2] + fusc[(n+1)/2]);
        }
    }
}
Task: Fusc sequence


C++: #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

const int n = 61;
std::vector<int> l{ 0, 1 };

int fusc(int n) {
    if (n < l.size()) return l[n];
    int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
    l.push_back(f);
    return f;
}

int main() {
    bool lst = true;
    int w = -1;
    int c = 0;
    int t;
    std::string res;
    std::cout << "First " << n << " numbers in the fusc sequence:\n";
    for (int i = 0; i < INT32_MAX; i++) {
        int f = fusc(i);
        if (lst) {
            if (i < 61) {
                std::cout << f << ' ';
            } else {
                lst = false;
                std::cout << "\nPoints in the sequence where an item has more digits than any previous items:\n";
                std::cout << std::setw(11) << "Index\\" << "  " << std::left << std::setw(9) << "/Value\n";
                std::cout << res << '\n';
                res = "";
            }
        }
        std::stringstream ss;
        ss << f;
        t = ss.str().length();
        ss.str("");
        ss.clear();
        if (t > w) {
            w = t;
            res += (res == "" ? "" : "\n");
            ss << std::setw(11) << i << "  " << std::left << std::setw(9) << f;
            res += ss.str();
            if (!lst) {
                std::cout << res << '\n';
                res = "";
            }
            if (++c > 5) {
                break;
            }
        }
    }
    return 0;
}






Python: from collections import deque
from itertools import islice, count


def fusc():
    q = deque([1])
    yield 0
    yield 1

    while True:
        x = q.popleft()
        q.append(x)
        yield x

        x += q[0]
        q.append(x)
        yield x


def longest_fusc():
    sofar = 0
    for i, f in zip(count(), fusc()):
        if f >= sofar:
            yield(i, f)
            sofar = 10 * sofar or 10


print('First 61:')
print(list(islice(fusc(), 61)))

print('\nLength records:')
for i, f in islice(longest_fusc(), 6):
    print(f'fusc({i}) = {f}')