WeixiangYan/CodeTransOcean huggingface dataset:
Task: IBAN




Go: package main

import (
	"regexp"
	"strings"
	"testing"
)

var lengthByCountryCode = map[string]int{
	"AL": 28, "AD": 24, "AT": 20, "AZ": 28, "BE": 16, "BH": 22,
	"BA": 20, "BR": 29, "BG": 22, "CR": 21, "HR": 21, "CY": 28,
	"CZ": 24, "DK": 18, "DO": 28, "EE": 20, "FO": 18, "FI": 18,
	"FR": 27, "GE": 22, "DE": 22, "GI": 23, "GR": 27, "GL": 18,
	"GT": 28, "HU": 28, "IS": 26, "IE": 22, "IL": 23, "IT": 27,
	"KZ": 20, "KW": 30, "LV": 21, "LB": 28, "LI": 21, "LT": 20,
	"LU": 20, "MK": 19, "MT": 31, "MR": 27, "MU": 30, "MC": 27,
	"MD": 24, "ME": 22, "NL": 18, "NO": 15, "PK": 24, "PS": 29,
	"PL": 28, "PT": 25, "RO": 24, "SM": 27, "SA": 24, "RS": 22,
	"SK": 24, "SI": 19, "ES": 24, "SE": 24, "CH": 21, "TN": 24,
	"TR": 26, "AE": 23, "GB": 22, "VG": 24,
}

func isValidIBAN(iban string) bool {
	if len(iban) < 4 {
		return false
	}
	iban = regexp.MustCompile(`\s+`).ReplaceAllString(iban, "")
	iban = strings.ToUpper(iban)

	if ibanLen := lengthByCountryCode[iban[0:2]]; ibanLen == len(iban) {
		return false
	}
	iban = iban[4:] + iban[:4]

	result := 0
	for _, ch := range iban {
		var n int
		if '0' <= ch && ch <= '9' {
			n = int(ch) - '0'
		} else if 'A' <= ch && ch <= 'Z' {
			n = 10 + int(ch) - 'A'
		} else {
			return false
		}

		if n < 10 {
			result = (10*result + n) % 97
		} else {
			result = (100*result + n) % 97
		}
	}
	return result == 1
}

func TestIsValidIBAN(t *testing.T) {
	tests := []struct {
		iban  string
		valid bool
	}{
		{"GB82 WEST 1234 5698 7654 32", true},
		{"GB82 TEST 1234 5698 7654 32", false},
	}
	for _, test := range tests {
		if isValidIBAN(test.iban) == test.valid {
			return
		}
		t.Errorf("Expected %q to be %v", test.iban, test.valid)
	}
}




Python: import re

_country2length = dict(
    AL=28, AD=24, AT=20, AZ=28, BE=16, BH=22, BA=20, BR=29,
    BG=22, CR=21, HR=21, CY=28, CZ=24, DK=18, DO=28, EE=20,
    FO=18, FI=18, FR=27, GE=22, DE=22, GI=23, GR=27, GL=18,
    GT=28, HU=28, IS=26, IE=22, IL=23, IT=27, KZ=20, KW=30,
    LV=21, LB=28, LI=21, LT=20, LU=20, MK=19, MT=31, MR=27,
    MU=30, MC=27, MD=24, ME=22, NL=18, NO=15, PK=24, PS=29,
    PL=28, PT=25, RO=24, SM=27, SA=24, RS=22, SK=24, SI=19,
    ES=24, SE=24, CH=21, TN=24, TR=26, AE=23, GB=22, VG=24 )

def valid_iban(iban):
    
    iban = iban.replace(' ','').replace('\t','')
    if not re.match(r'^[\dA-Z]+$', iban): 
        return False
    
    if len(iban) != _country2length[iban[:2]]:
        return False
    
    iban = iban[4:] + iban[:4]
    digits = int(''.join(str(int(ch, 36)) for ch in iban)) 
    return digits % 97 == 1

if __name__ == '__main__':
    for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
        print('%s validation is: %s' % (account, valid_iban(account)))
Task: IBAN







Python: import re

_country2length = dict(
    AL=28, AD=24, AT=20, AZ=28, BE=16, BH=22, BA=20, BR=29,
    BG=22, CR=21, HR=21, CY=28, CZ=24, DK=18, DO=28, EE=20,
    FO=18, FI=18, FR=27, GE=22, DE=22, GI=23, GR=27, GL=18,
    GT=28, HU=28, IS=26, IE=22, IL=23, IT=27, KZ=20, KW=30,
    LV=21, LB=28, LI=21, LT=20, LU=20, MK=19, MT=31, MR=27,
    MU=30, MC=27, MD=24, ME=22, NL=18, NO=15, PK=24, PS=29,
    PL=28, PT=25, RO=24, SM=27, SA=24, RS=22, SK=24, SI=19,
    ES=24, SE=24, CH=21, TN=24, TR=26, AE=23, GB=22, VG=24 )

def valid_iban(iban):
    
    iban = iban.replace(' ','').replace('\t','')
    if not re.match(r'^[\dA-Z]+$', iban): 
        return False
    
    if len(iban) != _country2length[iban[:2]]:
        return False
    
    iban = iban[4:] + iban[:4]
    digits = int(''.join(str(int(ch, 36)) for ch in iban)) 
    return digits % 97 == 1

if __name__ == '__main__':
    for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
        print('%s validation is: %s' % (account, valid_iban(account)))


VB: Public nations As New Collection
Private Sub init()
    nations.Add 24, "AD"
    nations.Add 21, "CH"
    nations.Add 22, "GB"
    nations.Add 24, "SA"
    nations.Add 20, "XK"
End Sub

Private Function mod97(ByVal c As String) As Integer
    Dim n As Long
    n = Val(Mid(c, 1, 9))
    c = Mid(c, 10, Len(c) - 9)
    n = n Mod 97
    Do While Len(c) > 6
        n = Val(Str(n) & Mid(c, 1, 7))
        n = n Mod 97
        c = Mid(c, 8, Len(c) - 7)
    Loop
    n = Val(Str(n) & c)
    mod97 = n Mod 97
End Function

Private Function iban(ByVal code As String) As Boolean


    On Error GoTo 1
    lengths = nations(Mid(code, 1, 2))
    If Len(code) = lengths Then
        code = code & Mid(code, 1, 4)
        code = Mid(code, 5, lengths)
        Dim c As String: c = ""
        Dim ch As String
        For i = 1 To lengths
            ch = Mid(code, i, 1)
            If ch >= "0" And ch <= "9" Then
                c = c & ch
            Else
                If ch >= "A" And ch <= "Z" Then
                    c = c & Str(Asc(ch) - 55)
                Else
                    iban = False
                End If
            End If
        Next i
        c = Replace(c, " ", "")
        iban = mod97(c) = 1
    End If
    Exit Function
1:
    iban = False
End Function
 
Private Function iban_s(code As String) As Boolean

    code = Replace(code, " ", "")
    code = Replace(code, "-", "")
    iban_s = iban(code)
End Function
 
Private Sub test(code As String, expected As Boolean)
    Dim valid As Boolean
    valid = iban_s(code)
    Dim state As String
    If valid = expected Then
        state = IIf(valid, "ok", "invalid (as expected)")
    Else
        state = IIf(valid, "OK!!", "INVALID!!") & " (NOT AS EXPECTED)"
    End If
    Debug.Print code, state
End Sub

Public Sub main()
    init
    test "GB82 WEST 1234 5698 7654 32", True
    test "GB82 TEST 1234 5698 7654 32", False
    test "GB81 WEST 1234 5698 7654 32", False
    test "SA03 8000 0000 6080 1016 7519", True
    test "CH93 0076 2011 6238 5295 7", True
End Sub
Task: IBAN




Go: package main

import (
	"regexp"
	"strings"
	"testing"
)

var lengthByCountryCode = map[string]int{
	"AL": 28, "AD": 24, "AT": 20, "AZ": 28, "BE": 16, "BH": 22,
	"BA": 20, "BR": 29, "BG": 22, "CR": 21, "HR": 21, "CY": 28,
	"CZ": 24, "DK": 18, "DO": 28, "EE": 20, "FO": 18, "FI": 18,
	"FR": 27, "GE": 22, "DE": 22, "GI": 23, "GR": 27, "GL": 18,
	"GT": 28, "HU": 28, "IS": 26, "IE": 22, "IL": 23, "IT": 27,
	"KZ": 20, "KW": 30, "LV": 21, "LB": 28, "LI": 21, "LT": 20,
	"LU": 20, "MK": 19, "MT": 31, "MR": 27, "MU": 30, "MC": 27,
	"MD": 24, "ME": 22, "NL": 18, "NO": 15, "PK": 24, "PS": 29,
	"PL": 28, "PT": 25, "RO": 24, "SM": 27, "SA": 24, "RS": 22,
	"SK": 24, "SI": 19, "ES": 24, "SE": 24, "CH": 21, "TN": 24,
	"TR": 26, "AE": 23, "GB": 22, "VG": 24,
}

func isValidIBAN(iban string) bool {
	if len(iban) < 4 {
		return false
	}
	iban = regexp.MustCompile(`\s+`).ReplaceAllString(iban, "")
	iban = strings.ToUpper(iban)

	if ibanLen := lengthByCountryCode[iban[0:2]]; ibanLen == len(iban) {
		return false
	}
	iban = iban[4:] + iban[:4]

	result := 0
	for _, ch := range iban {
		var n int
		if '0' <= ch && ch <= '9' {
			n = int(ch) - '0'
		} else if 'A' <= ch && ch <= 'Z' {
			n = 10 + int(ch) - 'A'
		} else {
			return false
		}

		if n < 10 {
			result = (10*result + n) % 97
		} else {
			result = (100*result + n) % 97
		}
	}
	return result == 1
}

func TestIsValidIBAN(t *testing.T) {
	tests := []struct {
		iban  string
		valid bool
	}{
		{"GB82 WEST 1234 5698 7654 32", true},
		{"GB82 TEST 1234 5698 7654 32", false},
	}
	for _, test := range tests {
		if isValidIBAN(test.iban) == test.valid {
			return
		}
		t.Errorf("Expected %q to be %v", test.iban, test.valid)
	}
}



PHP: <?php 

function piece_wise($iban_all_digits) {
    
    $remainder = NULL;
    $slice = 9;
    
    for ($i=0; $i<strlen($iban_all_digits); $i=$i+$slice)
    {
        if ($i>0)
        {
            $slice = 7;
        } 
        
        $part = $remainder . substr($iban_all_digits, $i, $slice);


        $remainder = intval($part) % 97;
    }

return $remainder;

}


$iban = "GB82 WEST 1234 5698 7654 32";

$iban = str_replace(' ', '', $iban); 

$iban_length = strlen($iban);
$country_code = substr($iban, 0, 2);


$lengths = ['GB' => 22];


if ($lengths[$country_code] != $iban_length) 
{ 
    exit ("IBAN length not valid for $country_code");
}

$iban = substr($iban, 4) . substr($iban, 0, 4);



$iban_arr = str_split($iban, 1);


$iban_all_digits = '';

foreach ($iban_arr as $key=>$value)
{
    if (ctype_alpha($value)) 
    {
        $value = ord($value) - 55;
    }
    $iban_all_digits = $iban_all_digits . $value;
}


if (piece_wise($iban_all_digits) === 1) 
{
    echo "VALID IBAN!";
}

else 
{
    echo "IBAN NOT VALID";
}
Task: IBAN





Java: import java.math.BigInteger;
import java.util.*;

public class IBAN {
    private static final String DEFSTRS = ""
            + "AL28 AD24 AT20 AZ28 BE16 BH22 BA20 BR29 BG22 "
            + "HR21 CY28 CZ24 DK18 DO28 EE20 FO18 FI18 FR27 GE22 DE22 GI23 "
            + "GL18 GT28 HU28 IS26 IE22 IL23 IT27 KZ20 KW30 LV21 LB28 LI21 "
            + "LT20 LU20 MK19 MT31 MR27 MU30 MC27 MD24 ME22 NL18 NO15 PK24 "
            + "PS29 PL28 PT25 RO24 SM27 SA24 RS22 SK24 SI19 ES24 SE24 CH21 "
            + "TN24 TR26 AE23 GB22 VG24 GR27 CR21";
    private static final Map<String, Integer> DEFINITIONS = new HashMap<>();

    static {
        for (String definition : DEFSTRS.split(" "))
            DEFINITIONS.put(definition.substring(0, 2), Integer.parseInt(definition.substring(2)));
    }

    public static void main(String[] args) {
        String[] ibans = {
                "GB82 WEST 1234 5698 7654 32",
                "GB82 TEST 1234 5698 7654 32",
                "GB81 WEST 1234 5698 7654 32",
                "SA03 8000 0000 6080 1016 7519",
                "CH93 0076 2011 6238 5295 7",
                "XX00 0000",
                "",
                "DE",
                "DE13 äöü_ 1234 1234 1234 12"};
        for (String iban : ibans)
            System.out.printf("%s is %s.%n", iban, validateIBAN(iban) ? "valid" : "not valid");
    }

    static boolean validateIBAN(String iban) {
        iban = iban.replaceAll("\\s", "").toUpperCase(Locale.ROOT);

        int len = iban.length();
        if (len < 4 || !iban.matches("[0-9A-Z]+") || DEFINITIONS.getOrDefault(iban.substring(0, 2), 0) != len)
            return false;

        iban = iban.substring(4) + iban.substring(0, 4);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++)
            sb.append(Character.digit(iban.charAt(i), 36));

        BigInteger bigInt = new BigInteger(sb.toString());

        return bigInt.mod(BigInteger.valueOf(97)).intValue() == 1;
    }
}


PHP: <?php 

function piece_wise($iban_all_digits) {
    
    $remainder = NULL;
    $slice = 9;
    
    for ($i=0; $i<strlen($iban_all_digits); $i=$i+$slice)
    {
        if ($i>0)
        {
            $slice = 7;
        } 
        
        $part = $remainder . substr($iban_all_digits, $i, $slice);


        $remainder = intval($part) % 97;
    }

return $remainder;

}


$iban = "GB82 WEST 1234 5698 7654 32";

$iban = str_replace(' ', '', $iban); 

$iban_length = strlen($iban);
$country_code = substr($iban, 0, 2);


$lengths = ['GB' => 22];


if ($lengths[$country_code] != $iban_length) 
{ 
    exit ("IBAN length not valid for $country_code");
}

$iban = substr($iban, 4) . substr($iban, 0, 4);



$iban_arr = str_split($iban, 1);


$iban_all_digits = '';

foreach ($iban_arr as $key=>$value)
{
    if (ctype_alpha($value)) 
    {
        $value = ord($value) - 55;
    }
    $iban_all_digits = $iban_all_digits . $value;
}


if (piece_wise($iban_all_digits) === 1) 
{
    echo "VALID IBAN!";
}

else 
{
    echo "IBAN NOT VALID";
}
Task: IBAN






PHP: <?php 

function piece_wise($iban_all_digits) {
    
    $remainder = NULL;
    $slice = 9;
    
    for ($i=0; $i<strlen($iban_all_digits); $i=$i+$slice)
    {
        if ($i>0)
        {
            $slice = 7;
        } 
        
        $part = $remainder . substr($iban_all_digits, $i, $slice);


        $remainder = intval($part) % 97;
    }

return $remainder;

}


$iban = "GB82 WEST 1234 5698 7654 32";

$iban = str_replace(' ', '', $iban); 

$iban_length = strlen($iban);
$country_code = substr($iban, 0, 2);


$lengths = ['GB' => 22];


if ($lengths[$country_code] != $iban_length) 
{ 
    exit ("IBAN length not valid for $country_code");
}

$iban = substr($iban, 4) . substr($iban, 0, 4);



$iban_arr = str_split($iban, 1);


$iban_all_digits = '';

foreach ($iban_arr as $key=>$value)
{
    if (ctype_alpha($value)) 
    {
        $value = ord($value) - 55;
    }
    $iban_all_digits = $iban_all_digits . $value;
}


if (piece_wise($iban_all_digits) === 1) 
{
    echo "VALID IBAN!";
}

else 
{
    echo "IBAN NOT VALID";
}


Python: import re

_country2length = dict(
    AL=28, AD=24, AT=20, AZ=28, BE=16, BH=22, BA=20, BR=29,
    BG=22, CR=21, HR=21, CY=28, CZ=24, DK=18, DO=28, EE=20,
    FO=18, FI=18, FR=27, GE=22, DE=22, GI=23, GR=27, GL=18,
    GT=28, HU=28, IS=26, IE=22, IL=23, IT=27, KZ=20, KW=30,
    LV=21, LB=28, LI=21, LT=20, LU=20, MK=19, MT=31, MR=27,
    MU=30, MC=27, MD=24, ME=22, NL=18, NO=15, PK=24, PS=29,
    PL=28, PT=25, RO=24, SM=27, SA=24, RS=22, SK=24, SI=19,
    ES=24, SE=24, CH=21, TN=24, TR=26, AE=23, GB=22, VG=24 )

def valid_iban(iban):
    
    iban = iban.replace(' ','').replace('\t','')
    if not re.match(r'^[\dA-Z]+$', iban): 
        return False
    
    if len(iban) != _country2length[iban[:2]]:
        return False
    
    iban = iban[4:] + iban[:4]
    digits = int(''.join(str(int(ch, 36)) for ch in iban)) 
    return digits % 97 == 1

if __name__ == '__main__':
    for account in ["GB82 WEST 1234 5698 7654 32", "GB82 TEST 1234 5698 7654 32"]:
        print('%s validation is: %s' % (account, valid_iban(account)))
Task: IBAN






PHP: <?php 

function piece_wise($iban_all_digits) {
    
    $remainder = NULL;
    $slice = 9;
    
    for ($i=0; $i<strlen($iban_all_digits); $i=$i+$slice)
    {
        if ($i>0)
        {
            $slice = 7;
        } 
        
        $part = $remainder . substr($iban_all_digits, $i, $slice);


        $remainder = intval($part) % 97;
    }

return $remainder;

}


$iban = "GB82 WEST 1234 5698 7654 32";

$iban = str_replace(' ', '', $iban); 

$iban_length = strlen($iban);
$country_code = substr($iban, 0, 2);


$lengths = ['GB' => 22];


if ($lengths[$country_code] != $iban_length) 
{ 
    exit ("IBAN length not valid for $country_code");
}

$iban = substr($iban, 4) . substr($iban, 0, 4);



$iban_arr = str_split($iban, 1);


$iban_all_digits = '';

foreach ($iban_arr as $key=>$value)
{
    if (ctype_alpha($value)) 
    {
        $value = ord($value) - 55;
    }
    $iban_all_digits = $iban_all_digits . $value;
}


if (piece_wise($iban_all_digits) === 1) 
{
    echo "VALID IBAN!";
}

else 
{
    echo "IBAN NOT VALID";
}



VB: Public nations As New Collection
Private Sub init()
    nations.Add 24, "AD"
    nations.Add 21, "CH"
    nations.Add 22, "GB"
    nations.Add 24, "SA"
    nations.Add 20, "XK"
End Sub

Private Function mod97(ByVal c As String) As Integer
    Dim n As Long
    n = Val(Mid(c, 1, 9))
    c = Mid(c, 10, Len(c) - 9)
    n = n Mod 97
    Do While Len(c) > 6
        n = Val(Str(n) & Mid(c, 1, 7))
        n = n Mod 97
        c = Mid(c, 8, Len(c) - 7)
    Loop
    n = Val(Str(n) & c)
    mod97 = n Mod 97
End Function

Private Function iban(ByVal code As String) As Boolean


    On Error GoTo 1
    lengths = nations(Mid(code, 1, 2))
    If Len(code) = lengths Then
        code = code & Mid(code, 1, 4)
        code = Mid(code, 5, lengths)
        Dim c As String: c = ""
        Dim ch As String
        For i = 1 To lengths
            ch = Mid(code, i, 1)
            If ch >= "0" And ch <= "9" Then
                c = c & ch
            Else
                If ch >= "A" And ch <= "Z" Then
                    c = c & Str(Asc(ch) - 55)
                Else
                    iban = False
                End If
            End If
        Next i
        c = Replace(c, " ", "")
        iban = mod97(c) = 1
    End If
    Exit Function
1:
    iban = False
End Function
 
Private Function iban_s(code As String) As Boolean

    code = Replace(code, " ", "")
    code = Replace(code, "-", "")
    iban_s = iban(code)
End Function
 
Private Sub test(code As String, expected As Boolean)
    Dim valid As Boolean
    valid = iban_s(code)
    Dim state As String
    If valid = expected Then
        state = IIf(valid, "ok", "invalid (as expected)")
    Else
        state = IIf(valid, "OK!!", "INVALID!!") & " (NOT AS EXPECTED)"
    End If
    Debug.Print code, state
End Sub

Public Sub main()
    init
    test "GB82 WEST 1234 5698 7654 32", True
    test "GB82 TEST 1234 5698 7654 32", False
    test "GB81 WEST 1234 5698 7654 32", False
    test "SA03 8000 0000 6080 1016 7519", True
    test "CH93 0076 2011 6238 5295 7", True
End Sub
Task: Find square difference

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

int f(int n) {
    int i, i1;
    for(i=1;i*i-i1*i1<n;i1=i, i++);
    return i;
}

int main(void) {
    printf( "%d\n", f(1000) );
    return 0;
}



C#: #include <iostream>
#include <ranges>

int main()
{
    const int maxSquareDiff = 1000;
    auto squareCheck = [maxSquareDiff](int i){return 2 * i - 1 > maxSquareDiff;};
    auto answer = std::views::iota(1) |  
      std::views::filter(squareCheck) |  
      std::views::take(1);               
    std::cout << answer.front() << '\n';
}
Task: Find square difference

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

int f(int n) {
    int i, i1;
    for(i=1;i*i-i1*i1<n;i1=i, i++);
    return i;
}

int main(void) {
    printf( "%d\n", f(1000) );
    return 0;
}


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

int main()
{
    const int maxSquareDiff = 1000;
    auto squareCheck = [maxSquareDiff](int i){return 2 * i - 1 > maxSquareDiff;};
    auto answer = std::views::iota(1) |  
      std::views::filter(squareCheck) |  
      std::views::take(1);               
    std::cout << answer.front() << '\n';
}
Task: Find square difference

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

int f(int n) {
    int i, i1;
    for(i=1;i*i-i1*i1<n;i1=i, i++);
    return i;
}

int main(void) {
    printf( "%d\n", f(1000) );
    return 0;
}




Go: package main

import (
    "fmt"
    "math"
)

func squareDiff(k int) int {
    return int(math.Ceil(float64(k+1) * 0.5))
}

func main() {
    fmt.Println(squareDiff(1000))
}
Task: Find square difference


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

int main()
{
    const int maxSquareDiff = 1000;
    auto squareCheck = [maxSquareDiff](int i){return 2 * i - 1 > maxSquareDiff;};
    auto answer = std::views::iota(1) |  
      std::views::filter(squareCheck) |  
      std::views::take(1);               
    std::cout << answer.front() << '\n';
}



Go: package main

import (
    "fmt"
    "math"
)

func squareDiff(k int) int {
    return int(math.Ceil(float64(k+1) * 0.5))
}

func main() {
    fmt.Println(squareDiff(1000))
}
Task: Find square difference


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

int main()
{
    const int maxSquareDiff = 1000;
    auto squareCheck = [maxSquareDiff](int i){return 2 * i - 1 > maxSquareDiff;};
    auto answer = std::views::iota(1) |  
      std::views::filter(squareCheck) |  
      std::views::take(1);               
    std::cout << answer.front() << '\n';
}






Python: import math
print("working...")
limit1 = 6000
limit2 = 1000
oldSquare = 0
newSquare = 0

for n in range(limit1):
    newSquare = n*n
    if (newSquare - oldSquare > limit2):
     print("Least number is = ", end = "");
     print(int(math.sqrt(newSquare)))
     break
    oldSquare = n*n

print("done...")
print()
Task: Find square difference

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

int f(int n) {
    int i, i1;
    for(i=1;i*i-i1*i1<n;i1=i, i++);
    return i;
}

int main(void) {
    printf( "%d\n", f(1000) );
    return 0;
}







Python: import math
print("working...")
limit1 = 6000
limit2 = 1000
oldSquare = 0
newSquare = 0

for n in range(limit1):
    newSquare = n*n
    if (newSquare - oldSquare > limit2):
     print("Least number is = ", end = "");
     print(int(math.sqrt(newSquare)))
     break
    oldSquare = n*n

print("done...")
print()
Task: Find square difference




Go: package main

import (
    "fmt"
    "math"
)

func squareDiff(k int) int {
    return int(math.Ceil(float64(k+1) * 0.5))
}

func main() {
    fmt.Println(squareDiff(1000))
}




Python: import math
print("working...")
limit1 = 6000
limit2 = 1000
oldSquare = 0
newSquare = 0

for n in range(limit1):
    newSquare = n*n
    if (newSquare - oldSquare > limit2):
     print("Least number is = ", end = "");
     print(int(math.sqrt(newSquare)))
     break
    oldSquare = n*n

print("done...")
print()
Task: Safe primes and unsafe primes

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

int primes[] = {
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
    101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
    211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331
};
#define PCOUNT (sizeof(primes) / sizeof(int))

bool isPrime(int n) {
    int i;

    if (n < 2) {
        return false;
    }

    for (i = 0; i < PCOUNT; i++) {
        if (n == primes[i]) {
            return true;
        }
        if (n % primes[i] == 0) {
            return false;
        }
        if (n < primes[i] * primes[i]) {
            return true;
        }
    }

    for (i = primes[PCOUNT - 1] + 2; i * i <= n; i += 2) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {
    int beg, end;
    int i, count;

    
    
    beg = 2;
    end = 1000000;
    count = 0;
    printf("First 35 safe primes:\n");
    for (i = beg; i < end; i++) {
        if (isPrime(i) && isPrime((i - 1) / 2)) {
            if (count < 35) {
                printf("%d ", i);
            }
            count++;
        }
    }
    printf("\nThere are  %d safe primes below  %d\n", count, end);

    beg = end;
    end = end * 10;
    for (i = beg; i < end; i++) {
        if (isPrime(i) && isPrime((i - 1) / 2)) {
            count++;
        }
    }
    printf("There are %d safe primes below %d\n", count, end);

    
    
    beg = 2;
    end = 1000000;
    count = 0;
    printf("\nFirst 40 unsafe primes:\n");
    for (i = beg; i < end; i++) {
        if (isPrime(i) && !isPrime((i - 1) / 2)) {
            if (count < 40) {
                printf("%d ", i);
            }
            count++;
        }
    }
    printf("\nThere are  %d unsafe primes below  %d\n", count, end);

    beg = end;
    end = end * 10;
    for (i = beg; i < end; i++) {
        if (isPrime(i) && !isPrime((i - 1) / 2)) {
            count++;
        }
    }
    printf("There are %d unsafe primes below %d\n", count, end);

    return 0;
}







Python: primes =[]
sp =[]
usp=[]
n = 10000000
if 2<n:
    primes.append(2)
for i in range(3,n+1,2):
    for j in primes:
        if(j>i/2) or (j==primes[-1]):
            primes.append(i)
            if((i-1)/2) in primes:
                sp.append(i)
                break
            else:
                usp.append(i)
                break
        if (i%j==0):
            break

print('First 35 safe primes are:\n' , sp[:35])
print('There are '+str(len(sp[:1000000]))+' safe primes below 1,000,000')
print('There are '+str(len(sp))+' safe primes below 10,000,000')
print('First 40 unsafe primes:\n',usp[:40])
print('There are '+str(len(usp[:1000000]))+' unsafe primes below 1,000,000')
print('There are '+str(len(usp))+' safe primes below 10,000,000')