kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Amicable pairs
C++: #include <vector>
#include <unordered_map>
#include <iostream>

int main() {
    std::vector<int> alreadyDiscovered;
    std::unordered_map<int, int> divsumMap; 
    int count = 0;

    for (int N = 1; N <= 20000; ++N)
    {      
        int divSumN = 0;

        for (int i = 1; i <= N / 2; ++i)
        {
            if (fmod(N, i) == 0)
            {
                divSumN += i;
            }
        }
        
        
        if (divSumN != 1) 
            divsumMap[N] = divSumN;

        for (std::unordered_map<int, int>::iterator it = divsumMap.begin(); it != divsumMap.end(); ++it)
        {
            int M = it->first;
            int divSumM = it->second;
            int divSumN = divsumMap[N];

            if (N != M && divSumM == N && divSumN == M)
            {
                
                if (std::find(alreadyDiscovered.begin(), alreadyDiscovered.end(), N) != alreadyDiscovered.end())
                    break;

                std::cout << "[" << M << ", " << N << "]" << std::endl;

                alreadyDiscovered.push_back(M);
                alreadyDiscovered.push_back(N);
                count++;
            }
        }
    }

    std::cout << count << " amicable pairs discovered" << std::endl;
}

Java: import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

public class AmicablePairs {

    public static void main(String[] args) {
        int limit = 20_000;

        Map<Long, Long> map = LongStream.rangeClosed(1, limit)
                .parallel()
                .boxed()
                .collect(Collectors.toMap(Function.identity(), AmicablePairs::properDivsSum));

        LongStream.rangeClosed(1, limit)
                .forEach(n -> {
                    long m = map.get(n);
                    if (m > n && m <= limit && map.get(m) == n)
                        System.out.printf("%s %s %n", n, m);
                });
    }

    public static Long properDivsSum(long n) {
        return LongStream.rangeClosed(1, (n + 1) / 2).filter(i -> n % i == 0).sum();
    }
}
Task: Amicable pairs
Go: package main

import "fmt"

func pfacSum(i int) int {
    sum := 0
    for p := 1; p <= i/2; p++ {
        if i%p == 0 {
            sum += p
        }
    }
    return sum
}

func main() {
    var a[20000]int
    for i := 1; i < 20000; i++ {
        a[i] = pfacSum(i)
    }
    fmt.Println("The amicable pairs below 20,000 are:")
    for n := 2; n < 19999; n++ {
        m := a[n]
        if m > n && m < 20000 && n == a[m] {
            fmt.Printf("  %5d and %5d\n", n, m)
        } 
    }
}

VB: dim sums(20000)

sub sum_proper_divisors(n)
	dim sum = 0
	dim i
	if n > 1 then
		for i = 1 to (n \ 2)
			if n %% i = 0 then
				sum = sum + i 
			end if
		next
	end if
	return sum
end sub

dim i, j
for i = 1 to 20000
	sums(i) = sum_proper_divisors(i)
	for j = i-1 to 2 by -1
		if sums(i) = j and sums(j) = i then
			print "Amicable pair:";sums(i);"-";sums(j)
			exit for
		end if
	next 
next
Task: Amicable pairs
C: #include <stdio.h>
#include <stdlib.h>

typedef unsigned int uint;

int main(int argc, char **argv)
{
  uint top = atoi(argv[1]);
  uint *divsum = malloc((top + 1) * sizeof(*divsum));
  uint pows[32] = {1, 0};

  for (uint i = 0; i <= top; i++) divsum[i] = 1;

  
  
  for (uint p = 2; p+p <= top; p++) {
    if (divsum[p] > 1) {
      divsum[p] -= p;
      continue;}     

    uint x; 
    
    for (x = 1; pows[x - 1] <= top/p; x++)
      pows[x] = p*pows[x - 1];

    
    
    
    uint k= p-1;
    for (uint n = p+p; n <= top; n += p) {
      uint s=1+pows[1];
      k--;
      
      if ( k==0) {
        for (uint i = 2; i < x && !(n%pows[i]); s += pows[i++]);
        k = p; }
      divsum[n] *= s;
    }
  }

  
  for (uint p = (top >> 1)+1; p <= top; p++) {
    if (divsum[p] > 1){
      divsum[p] -= p;}
  }

  uint cnt = 0;
  for (uint a = 1; a <= top; a++) {
    uint b = divsum[a];
    if (b > a && b <= top && divsum[b] == a){
      printf("%u %u\n", a, b);
      cnt++;}
  }
  printf("\nTop %u count : %u\n",top,cnt);
  return 0;
}

Go: package main

import "fmt"

func pfacSum(i int) int {
    sum := 0
    for p := 1; p <= i/2; p++ {
        if i%p == 0 {
            sum += p
        }
    }
    return sum
}

func main() {
    var a[20000]int
    for i := 1; i < 20000; i++ {
        a[i] = pfacSum(i)
    }
    fmt.Println("The amicable pairs below 20,000 are:")
    for n := 2; n < 19999; n++ {
        m := a[n]
        if m > n && m < 20000 && n == a[m] {
            fmt.Printf("  %5d and %5d\n", n, m)
        } 
    }
}
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} );
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} );
Task: Empty string
C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} ); 

Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}
Task: Empty string
C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} ); 

Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True
Task: Empty string
C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} ); 

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0 

Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}
Task: Empty string
Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}

Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True
Task: Empty string
Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0 

Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True
Task: Empty string
Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0 

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True

VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."
Task: Empty string
C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} ); 

Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0
Task: Empty string
C: #include <string.h>




const char *str = "";


if (str) { ... }


if (str[0] == '\0') { ... }


if ( (str == NULL) || (strlen(str) == 0)) { ... }


if (strcmp(str, "") == 0) { ... }

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
C#: using System;

namespace EmptyString
{
  class Program
  {
    public static void Main()
    {
      String s = scope .();
      if (s.IsEmpty)
      {
        Console.Writeln("string empty");
      }
      if (!s.IsEmpty)
      {
        Console.Writeln("string not empty");
      }
    }
  }
}

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
C++: #include <string>




                     
std::string str;     
std::string str();   
std::string str{};   
std::string str(""); 
std::string str{""}; 



if (str.empty()) { ... } 


if (str.length() == 0) { ... }
if (str == "") { ... }


str.clear();          
str = "";             
str = {};             

                       
std::string tmp{};     
str.swap(tmp);         
std::swap(str, tmp);   



std::string  s_array[100];           
std::array<std::string, 100>  arr;   
std::vector<std::string>(100,"");    


void func( std::string& s = {} ); 

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
Go: 
var s string
s2 := ""


s = ""


s == ""
len(s) == 0


s != ""
len(s) != 0 

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
Java: String s = "";
if(s != null && s.isEmpty()){
   System.out.println("s is empty");
}else{
   System.out.println("s is not empty");
}

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
Python: s = ''

s = str()

if not s or s == '':
   print("String is empty")

if len(s) == 0:
    print("String is empty")
else:
    print("String not empty")






def emptystring(s):
   if isinstance(s, (''.__class__ , u''.__class__) ):
      if len(s) == 0: 
         return True
      else 
         return False

   elif s is None:
        return True

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Empty string
VB: dim s as string


s = ""

s = vbNullString



if s = "" then Debug.Print "empty!"

if Len(s) = 0 then Debug.Print "still empty!"


if s <> "" then Debug.Print "not an empty string"

if Len(s) > 0 then Debug.Print "not empty."

PHP: <?php

$str = ''; // assign an empty string to a variable

if (empty($str)) { ... }

if (! empty($str)) { ... }

if ($str == '') { ... }
if ($str != '') { ... }

if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... }
Task: Split a character string based on change of character
C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}

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

public class Program
{
    string s = @"gHHH5YY++
    Console.WriteLine(s.RunLengthSplit().Delimit(", "));
}

public static class Extensions
{
    public static IEnumerable<string> RunLengthSplit(this string source) {
        using (var enumerator = source.GetEnumerator()) {
            if (!enumerator.MoveNext()) yield break;
            char previous = enumerator.Current;
            int count = 1;
            while (enumerator.MoveNext()) {
                if (previous == enumerator.Current) {
                    count++;
                } else {
                    yield return new string(Enumerable.Repeat(previous, count).ToArray());
                    previous = enumerator.Current;
                    count = 1;
                }
            }
            yield return new string(Enumerable.Repeat(previous, count).ToArray());
        }
    }

    public static string Delimit<T>(this IEnumerable<T> source, string separator = "") => string.Join(separator ?? "", source);
}
Task: Split a character string based on change of character
C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}

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

auto split(const std::string& input, const std::string& delim){
	std::string res;
	for(auto ch : input){
		if(!res.empty() && ch != res.back())
			res += delim;
		res += ch;
	}
	return res;
}

int main(){
	std::cout << split("gHHH5  ))YY++,,,
}
Task: Split a character string based on change of character
C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *split(char *str);
int main(int argc,char **argv)
{
	char input[13]="gHHH5YY++
	printf("%s\n",split(input));
}
char *split(char *str)
{
	char last=*str,*result=malloc(3*strlen(str)),*counter=result;
	for (char *c=str;*c;c++) {
		if (*c!=last) {
			strcpy(counter,", ");
			counter+=2;
			last=*c;
		}
		*counter=*c;
		counter++;
	}
	*(counter--)='\0';
	return realloc(result,strlen(result));
}

Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(scc(`gHHH5YY++
}

func scc(s string) string {
    if len(s) < 2 {
        return s
    }
    var b strings.Builder
    p := s[0]
    b.WriteByte(p)
    for _, c := range []byte(s[1:]) {
        if c != p {
            b.WriteString(", ")
        }
        b.WriteByte(c)
        p = c
    }
    return b.String()
}