WeixiangYan/CodeTransOcean huggingface dataset:
Task: Diversity prediction theorem

C: #include<string.h>
#include<stdlib.h>
#include<stdio.h>

float mean(float* arr,int size){
	int i = 0;
	float sum = 0;
	
	while(i != size)
		sum += arr[i++];
	
	return sum/size;
}

float variance(float reference,float* arr, int size){
	int i=0;
	float* newArr = (float*)malloc(size*sizeof(float));
	
	for(;i<size;i++)
		newArr[i] = (reference - arr[i])*(reference - arr[i]);
	
	return mean(newArr,size);
}

float* extractData(char* str, int *len){
	float* arr;
	int i=0,count = 1;
	char* token;
	
	while(str[i]!=00){
		if(str[i++]==',')
			count++;
	}
	
	arr = (float*)malloc(count*sizeof(float));
	*len = count;
	
	token = strtok(str,",");
	
	i = 0;
	
	while(token!=NULL){
		arr[i++] = atof(token);
		token = strtok(NULL,",");
	}
	
	return arr;
}

int main(int argC,char* argV[])
{
	float* arr,reference,meanVal;
	int len;
	if(argC!=3)
		printf("Usage : %s <reference value> <observations separated by commas>");
	else{
		arr = extractData(argV[2],&len);
		
		reference = atof(argV[1]);
		
		meanVal = mean(arr,len);

		printf("Average Error : %.9f\n",variance(reference,arr,len));
		printf("Crowd Error : %.9f\n",(reference - meanVal)*(reference - meanVal));
		printf("Diversity : %.9f",variance(meanVal,arr,len));
	}
	
	return 0;
}








VB: Module Module1

    Function Square(x As Double) As Double
        Return x * x
    End Function

    Function AverageSquareDiff(a As Double, predictions As IEnumerable(Of Double)) As Double
        Return predictions.Select(Function(x) Square(x - a)).Average()
    End Function

    Sub DiversityTheorem(truth As Double, predictions As IEnumerable(Of Double))
        Dim average = predictions.Average()
        Console.WriteLine("average-error: {0}", AverageSquareDiff(truth, predictions))
        Console.WriteLine("crowd-error: {0}", Square(truth - average))
        Console.WriteLine("diversity: {0}", AverageSquareDiff(average, predictions))
    End Sub

    Sub Main()
        DiversityTheorem(49.0, {48.0, 47.0, 51.0})
        DiversityTheorem(49.0, {48.0, 47.0, 51.0, 42.0})
    End Sub

End Module
Task: Base64 decode data

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

typedef unsigned char ubyte;
const ubyte BASE64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

int findIndex(const ubyte val) {
    if ('A' <= val && val <= 'Z') {
        return val - 'A';
    }
    if ('a' <= val && val <= 'z') {
        return val - 'a' + 26;
    }
    if ('0' <= val && val <= '9') {
        return val - '0' + 52;
    }
    if (val == '+') {
        return 62;
    }
    if (val == '/') {
        return 63;
    }
    return -1;
}

int decode(const ubyte source[], ubyte sink[]) {
    const size_t length = strlen(source);
    const ubyte *it = source;
    const ubyte *end = source + length;
    int acc;

    if (length % 4 != 0) {
        return 1;
    }

    while (it != end) {
        const ubyte b1 = *it++;
        const ubyte b2 = *it++;
        const ubyte b3 = *it++;         
        const ubyte b4 = *it++;         

        const int i1 = findIndex(b1);
        const int i2 = findIndex(b2);

        acc = i1 << 2;                  
        acc |= i2 >> 4;                 
        *sink++ = acc;                  

        if (b3 != '=') {
            const int i3 = findIndex(b3);

            acc = (i2 & 0xF) << 4;      
            acc += i3 >> 2;             
            *sink++ = acc;              

            if (b4 != '=') {
                const int i4 = findIndex(b4);

                acc = (i3 & 0x3) << 6;  
                acc |= i4;              
                *sink++ = acc;          
            }
        }
    }

    *sink = '\0';   
    return 0;
}

int main() {
    ubyte data[] = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo";
    ubyte decoded[1024];

    printf("%s\n\n", data);
    decode(data, decoded);
    printf("%s\n\n", decoded);

    return 0;
}



C#: using System;
using System.Text;

namespace Base64DecodeData {
    class Program {
        static void Main(string[] args) {
            var data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=";
            Console.WriteLine(data);
            Console.WriteLine();

            var decoded = Encoding.ASCII.GetString(Convert.FromBase64String(data));
            Console.WriteLine(decoded);
        }
    }
}
Task: Base64 decode data

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

typedef unsigned char ubyte;
const ubyte BASE64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

int findIndex(const ubyte val) {
    if ('A' <= val && val <= 'Z') {
        return val - 'A';
    }
    if ('a' <= val && val <= 'z') {
        return val - 'a' + 26;
    }
    if ('0' <= val && val <= '9') {
        return val - '0' + 52;
    }
    if (val == '+') {
        return 62;
    }
    if (val == '/') {
        return 63;
    }
    return -1;
}

int decode(const ubyte source[], ubyte sink[]) {
    const size_t length = strlen(source);
    const ubyte *it = source;
    const ubyte *end = source + length;
    int acc;

    if (length % 4 != 0) {
        return 1;
    }

    while (it != end) {
        const ubyte b1 = *it++;
        const ubyte b2 = *it++;
        const ubyte b3 = *it++;         
        const ubyte b4 = *it++;         

        const int i1 = findIndex(b1);
        const int i2 = findIndex(b2);

        acc = i1 << 2;                  
        acc |= i2 >> 4;                 
        *sink++ = acc;                  

        if (b3 != '=') {
            const int i3 = findIndex(b3);

            acc = (i2 & 0xF) << 4;      
            acc += i3 >> 2;             
            *sink++ = acc;              

            if (b4 != '=') {
                const int i4 = findIndex(b4);

                acc = (i3 & 0x3) << 6;  
                acc |= i4;              
                *sink++ = acc;          
            }
        }
    }

    *sink = '\0';   
    return 0;
}

int main() {
    ubyte data[] = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo";
    ubyte decoded[1024];

    printf("%s\n\n", data);
    decode(data, decoded);
    printf("%s\n\n", decoded);

    return 0;
}







Python: import base64
data = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g='
print(base64.b64decode(data).decode('utf-8'))
Task: Base64 decode data


C++: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef unsigned char ubyte;
const auto BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

std::vector<ubyte> encode(const std::vector<ubyte>& source) {
    auto it = source.cbegin();
    auto end = source.cend();

    std::vector<ubyte> sink;
    while (it != end) {
        auto b1 = *it++;
        int acc;

        sink.push_back(BASE64[b1 >> 2]);            

        acc = (b1 & 0x3) << 4;                      
        if (it != end) {
            auto b2 = *it++;
            acc |= (b2 >> 4);                       

            sink.push_back(BASE64[acc]);            

            acc = (b2 & 0xF) << 2;                  
            if (it != end) {
                auto b3 = *it++;
                acc |= (b3 >> 6);                   

                sink.push_back(BASE64[acc]);        
                sink.push_back(BASE64[b3 & 0x3F]);  
            } else {
                sink.push_back(BASE64[acc]);        
                sink.push_back('=');                
            }
        } else {
            sink.push_back(BASE64[acc]);            
            sink.push_back('=');                    
            sink.push_back('=');                    
        }
    }
    return sink;
}

int findIndex(ubyte val) {
    if ('A' <= val && val <= 'Z') {
        return val - 'A';
    }
    if ('a' <= val && val <= 'z') {
        return val - 'a' + 26;
    }
    if ('0' <= val && val <= '9') {
        return val - '0' + 52;
    }
    if ('+' == val) {
        return 62;
    }
    if ('/' == val) {
        return 63;
    }
    return -1;
}

std::vector<ubyte> decode(const std::vector<ubyte>& source) {
    if (source.size() % 4 != 0) {
        throw new std::runtime_error("Error in size to the decode method");
    }

    auto it = source.cbegin();
    auto end = source.cend();

    std::vector<ubyte> sink;
    while (it != end) {
        auto b1 = *it++;
        auto b2 = *it++;
        auto b3 = *it++; 
        auto b4 = *it++; 

        auto i1 = findIndex(b1);
        auto i2 = findIndex(b2);
        auto acc = i1 << 2;     
        acc |= i2 >> 4;         

        sink.push_back(acc);    

        if (b3 != '=') {
            auto i3 = findIndex(b3);

            acc = (i2 & 0xF) << 4;  
            acc |= i3 >> 2;         

            sink.push_back(acc);    

            if (b4 != '=') {
                auto i4 = findIndex(b4);

                acc = (i3 & 0x3) << 6;  
                acc |= i4;              

                sink.push_back(acc);    
            }
        }
    }
    return sink;
}

int main() {
    using namespace std;

    string data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo";
    vector<ubyte> datav{ begin(data), end(data) };
    cout << data << "\n\n" << decode(datav).data() << endl;

    return 0;
}






Python: import base64
data = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g='
print(base64.b64decode(data).decode('utf-8'))
Task: Base64 decode data



C#: using System;
using System.Text;

namespace Base64DecodeData {
    class Program {
        static void Main(string[] args) {
            var data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=";
            Console.WriteLine(data);
            Console.WriteLine();

            var decoded = Encoding.ASCII.GetString(Convert.FromBase64String(data));
            Console.WriteLine(decoded);
        }
    }
}





Python: import base64
data = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g='
print(base64.b64decode(data).decode('utf-8'))
Task: Base64 decode data

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

typedef unsigned char ubyte;
const ubyte BASE64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

int findIndex(const ubyte val) {
    if ('A' <= val && val <= 'Z') {
        return val - 'A';
    }
    if ('a' <= val && val <= 'z') {
        return val - 'a' + 26;
    }
    if ('0' <= val && val <= '9') {
        return val - '0' + 52;
    }
    if (val == '+') {
        return 62;
    }
    if (val == '/') {
        return 63;
    }
    return -1;
}

int decode(const ubyte source[], ubyte sink[]) {
    const size_t length = strlen(source);
    const ubyte *it = source;
    const ubyte *end = source + length;
    int acc;

    if (length % 4 != 0) {
        return 1;
    }

    while (it != end) {
        const ubyte b1 = *it++;
        const ubyte b2 = *it++;
        const ubyte b3 = *it++;         
        const ubyte b4 = *it++;         

        const int i1 = findIndex(b1);
        const int i2 = findIndex(b2);

        acc = i1 << 2;                  
        acc |= i2 >> 4;                 
        *sink++ = acc;                  

        if (b3 != '=') {
            const int i3 = findIndex(b3);

            acc = (i2 & 0xF) << 4;      
            acc += i3 >> 2;             
            *sink++ = acc;              

            if (b4 != '=') {
                const int i4 = findIndex(b4);

                acc = (i3 & 0x3) << 6;  
                acc |= i4;              
                *sink++ = acc;          
            }
        }
    }

    *sink = '\0';   
    return 0;
}

int main() {
    ubyte data[] = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo";
    ubyte decoded[1024];

    printf("%s\n\n", data);
    decode(data, decoded);
    printf("%s\n\n", decoded);

    return 0;
}






PHP: $encoded = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVw' .
           'IHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=';
echo
    $encoded, PHP_EOL,
    base64_decode($encoded), PHP_EOL;
Task: Base64 decode data



C#: using System;
using System.Text;

namespace Base64DecodeData {
    class Program {
        static void Main(string[] args) {
            var data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=";
            Console.WriteLine(data);
            Console.WriteLine();

            var decoded = Encoding.ASCII.GetString(Convert.FromBase64String(data));
            Console.WriteLine(decoded);
        }
    }
}




PHP: $encoded = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVw' .
           'IHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=';
echo
    $encoded, PHP_EOL,
    base64_decode($encoded), PHP_EOL;
Task: Base64 decode data






PHP: $encoded = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVw' .
           'IHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=';
echo
    $encoded, PHP_EOL,
    base64_decode($encoded), PHP_EOL;


Python: import base64
data = 'VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g='
print(base64.b64decode(data).decode('utf-8'))
Task: Largest difference between adjacent primes

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

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int nextprime( int p ) {
    int i=0;
    if(p==0) return 2;
    if(p<3) return p+1;
    while(!isprime(++i + p));
    return i+p;
}

int main(void) {
    int i=3, j=5, champ=3, champj=5, record=2;
    for(i=3;j<=1000000;i=j) {
        j=nextprime(i);
        if(j-i>record) {
            champ=i;
            champj=j;
            record = j-i;
        }
    }
    printf( "The largest difference was %d, between %d and %d.\n", record, champ, champj );
    return 0;
}



C#: #include <iostream>
#include <locale>

#include <primesieve.hpp>

int main() {
    std::cout.imbue(std::locale(""));
    const uint64_t limit = 10000000000;
    uint64_t max_diff = 0;
    primesieve::iterator pi;
    uint64_t p1 = pi.next_prime();
    for (uint64_t p = 10;;) {
        uint64_t p2 = pi.next_prime();
        if (p2 >= p) {
            std::cout << "Largest gap between primes under " << p << " is "
                      << max_diff << ".\n";
            if (p == limit)
                break;
            p *= 10;
        }
        if (p2 - p1 > max_diff)
            max_diff = p2 - p1;
        p1 = p2;
    }
}
Task: Largest difference between adjacent primes


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

#include <primesieve.hpp>

int main() {
    std::cout.imbue(std::locale(""));
    const uint64_t limit = 10000000000;
    uint64_t max_diff = 0;
    primesieve::iterator pi;
    uint64_t p1 = pi.next_prime();
    for (uint64_t p = 10;;) {
        uint64_t p2 = pi.next_prime();
        if (p2 >= p) {
            std::cout << "Largest gap between primes under " << p << " is "
                      << max_diff << ".\n";
            if (p == limit)
                break;
            p *= 10;
        }
        if (p2 - p1 > max_diff)
            max_diff = p2 - p1;
        p1 = p2;
    }
}



Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    limit := int(1e10 - 1)
    primes := rcu.Primes(limit)
    maxI := 0
    maxDiff := 0
    nextStop := 10
    fmt.Println("The largest differences between adjacent primes under the following limits is:")
    for i := 1; i < len(primes); i++ {
        diff := primes[i] - primes[i-1]
        if diff > maxDiff {
            maxDiff = diff
            maxI = i
        }
        if i == len(primes)-1 || primes[i+1] > nextStop {
            c1 := rcu.Commatize(nextStop)
            c2 := rcu.Commatize(primes[maxI])
            c3 := rcu.Commatize(primes[maxI-1])
            c4 := rcu.Commatize(maxDiff)
            fmt.Printf("Under %s: %s - %s = %s\n", c1, c2, c3, c4)
            nextStop *= 10
        }
    }
}
Task: Largest difference between adjacent primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    limit := int(1e10 - 1)
    primes := rcu.Primes(limit)
    maxI := 0
    maxDiff := 0
    nextStop := 10
    fmt.Println("The largest differences between adjacent primes under the following limits is:")
    for i := 1; i < len(primes); i++ {
        diff := primes[i] - primes[i-1]
        if diff > maxDiff {
            maxDiff = diff
            maxI = i
        }
        if i == len(primes)-1 || primes[i+1] > nextStop {
            c1 := rcu.Commatize(nextStop)
            c2 := rcu.Commatize(primes[maxI])
            c3 := rcu.Commatize(primes[maxI-1])
            c4 := rcu.Commatize(maxDiff)
            fmt.Printf("Under %s: %s - %s = %s\n", c1, c2, c3, c4)
            nextStop *= 10
        }
    }
}




Python: print("working...")
limit = 1000000
res1 = 0
res2 = 0
maxOld = 0
newDiff = 0
oldDiff = 0

def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

for n in range(limit):
    newDiff = n - maxOld
    if isprime(n):
       if (newDiff > oldDiff):
       	  res1 = n
       	  res2 = maxOld
          oldDiff = newDiff
       maxOld = n

diff = res1 - res2
print(res1)
print(res2)
print("Largest difference is = ",end="")
print(diff)
print("done...")
Task: Largest difference between adjacent primes

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

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int nextprime( int p ) {
    int i=0;
    if(p==0) return 2;
    if(p<3) return p+1;
    while(!isprime(++i + p));
    return i+p;
}

int main(void) {
    int i=3, j=5, champ=3, champj=5, record=2;
    for(i=3;j<=1000000;i=j) {
        j=nextprime(i);
        if(j-i>record) {
            champ=i;
            champj=j;
            record = j-i;
        }
    }
    printf( "The largest difference was %d, between %d and %d.\n", record, champ, champj );
    return 0;
}


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

#include <primesieve.hpp>

int main() {
    std::cout.imbue(std::locale(""));
    const uint64_t limit = 10000000000;
    uint64_t max_diff = 0;
    primesieve::iterator pi;
    uint64_t p1 = pi.next_prime();
    for (uint64_t p = 10;;) {
        uint64_t p2 = pi.next_prime();
        if (p2 >= p) {
            std::cout << "Largest gap between primes under " << p << " is "
                      << max_diff << ".\n";
            if (p == limit)
                break;
            p *= 10;
        }
        if (p2 - p1 > max_diff)
            max_diff = p2 - p1;
        p1 = p2;
    }
}
Task: Largest difference between adjacent primes

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

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int nextprime( int p ) {
    int i=0;
    if(p==0) return 2;
    if(p<3) return p+1;
    while(!isprime(++i + p));
    return i+p;
}

int main(void) {
    int i=3, j=5, champ=3, champj=5, record=2;
    for(i=3;j<=1000000;i=j) {
        j=nextprime(i);
        if(j-i>record) {
            champ=i;
            champj=j;
            record = j-i;
        }
    }
    printf( "The largest difference was %d, between %d and %d.\n", record, champ, champj );
    return 0;
}




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    limit := int(1e10 - 1)
    primes := rcu.Primes(limit)
    maxI := 0
    maxDiff := 0
    nextStop := 10
    fmt.Println("The largest differences between adjacent primes under the following limits is:")
    for i := 1; i < len(primes); i++ {
        diff := primes[i] - primes[i-1]
        if diff > maxDiff {
            maxDiff = diff
            maxI = i
        }
        if i == len(primes)-1 || primes[i+1] > nextStop {
            c1 := rcu.Commatize(nextStop)
            c2 := rcu.Commatize(primes[maxI])
            c3 := rcu.Commatize(primes[maxI-1])
            c4 := rcu.Commatize(maxDiff)
            fmt.Printf("Under %s: %s - %s = %s\n", c1, c2, c3, c4)
            nextStop *= 10
        }
    }
}
Task: Largest difference between adjacent primes

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

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int nextprime( int p ) {
    int i=0;
    if(p==0) return 2;
    if(p<3) return p+1;
    while(!isprime(++i + p));
    return i+p;
}

int main(void) {
    int i=3, j=5, champ=3, champj=5, record=2;
    for(i=3;j<=1000000;i=j) {
        j=nextprime(i);
        if(j-i>record) {
            champ=i;
            champj=j;
            record = j-i;
        }
    }
    printf( "The largest difference was %d, between %d and %d.\n", record, champ, champj );
    return 0;
}







Python: print("working...")
limit = 1000000
res1 = 0
res2 = 0
maxOld = 0
newDiff = 0
oldDiff = 0

def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

for n in range(limit):
    newDiff = n - maxOld
    if isprime(n):
       if (newDiff > oldDiff):
       	  res1 = n
       	  res2 = maxOld
          oldDiff = newDiff
       maxOld = n

diff = res1 - res2
print(res1)
print(res2)
print("Largest difference is = ",end="")
print(diff)
print("done...")
Task: Largest difference between adjacent primes


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

#include <primesieve.hpp>

int main() {
    std::cout.imbue(std::locale(""));
    const uint64_t limit = 10000000000;
    uint64_t max_diff = 0;
    primesieve::iterator pi;
    uint64_t p1 = pi.next_prime();
    for (uint64_t p = 10;;) {
        uint64_t p2 = pi.next_prime();
        if (p2 >= p) {
            std::cout << "Largest gap between primes under " << p << " is "
                      << max_diff << ".\n";
            if (p == limit)
                break;
            p *= 10;
        }
        if (p2 - p1 > max_diff)
            max_diff = p2 - p1;
        p1 = p2;
    }
}






Python: print("working...")
limit = 1000000
res1 = 0
res2 = 0
maxOld = 0
newDiff = 0
oldDiff = 0

def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

for n in range(limit):
    newDiff = n - maxOld
    if isprime(n):
       if (newDiff > oldDiff):
       	  res1 = n
       	  res2 = maxOld
          oldDiff = newDiff
       maxOld = n

diff = res1 - res2
print(res1)
print(res2)
print("Largest difference is = ",end="")
print(diff)
print("done...")
Task: Higher-order functions

C: void myFuncSimple( void (*funcParameter)(void) )
{
    
   
    (*funcParameter)();  
    funcParameter();     

    
}



C#: using System;


delegate int Func2(int a, int b);

class Program
{
    static int Add(int a, int b)
    {
        return a + b;
    }
    
    static int Mul(int a, int b)
    {
        return a * b;
    }
    
    static int Div(int a, int b)
    {
        return a / b;
    }
    
    static int Call(Func2 f, int a, int b)
    {
        
        return f(a, b);
    }

    static void Main()
    {
        int a = 6;
        int b = 2;

        
        Func2 add = new Func2(Add);
        Func2 mul = new Func2(Mul);
        Func2 div = new Func2(Div);
        
        Console.WriteLine("f=Add, f({0}, {1}) = {2}", a, b, Call(add, a, b));
        Console.WriteLine("f=Mul, f({0}, {1}) = {2}", a, b, Call(mul, a, b));
        Console.WriteLine("f=Div, f({0}, {1}) = {2}", a, b, Call(div, a, b));
    }
}