WeixiangYan/CodeTransOcean huggingface dataset:
Task: Character codes



C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}



Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }
Task: Character codes



C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}





Python: print ord('a') 
print chr(97)
Task: Character codes




Go: fmt.Println('a') 
fmt.Println('π') 


Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }
Task: Character codes





Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }



Python: print ord('a') 
print chr(97)
Task: Character codes





Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }




VB: TextWindow.WriteLine("The ascii code for 
TextWindow.WriteLine("The character for
Task: Character codes




Go: fmt.Println('a') 
fmt.Println('π') 





VB: TextWindow.WriteLine("The ascii code for 
TextWindow.WriteLine("The character for
Task: Character codes

C: #include <stdio.h>

int main() {
  printf("%d\n", 'a'); 
  printf("%c\n", 97); 
  return 0;
}








VB: TextWindow.WriteLine("The ascii code for 
TextWindow.WriteLine("The character for
Task: Character codes


C++: #include <iostream>

int main() {
  std::cout << (int)'a' << std::endl; 
  std::cout << (char)97 << std::endl; 
  return 0;
}


C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}
Task: Character codes


C++: #include <iostream>

int main() {
  std::cout << (int)'a' << std::endl; 
  std::cout << (char)97 << std::endl; 
  return 0;
}




Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }
Task: Character codes



C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}


Go: fmt.Println('a') 
fmt.Println('π')
Task: Character codes

C: #include <stdio.h>

int main() {
  printf("%d\n", 'a'); 
  printf("%c\n", 97); 
  return 0;
}





Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }
Task: Character codes



C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}






VB: TextWindow.WriteLine("The ascii code for 
TextWindow.WriteLine("The character for
Task: Character codes

C: #include <stdio.h>

int main() {
  printf("%d\n", 'a'); 
  printf("%c\n", 97); 
  return 0;
}






PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"
Task: Character codes



C#: using System;

namespace RosettaCode.CharacterCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int) 'a');   
            Console.WriteLine((char) 97);   
        }
    }
}




PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"
Task: Character codes


C++: #include <iostream>

int main() {
  std::cout << (int)'a' << std::endl; 
  std::cout << (char)97 << std::endl; 
  return 0;
}





PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"
Task: Character codes




Go: fmt.Println('a') 
fmt.Println('π') 



PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"
Task: Character codes





Java: module CharacterCodes
    {
    @Inject Console console;
    void run()
        {
        for (Char char : ['\0', '\d', 'A', '$', '¢', '~', '˜'])
            {
            
            UInt32 codepoint = char.codepoint;

            
            Char fromCodePoint = codepoint.toChar();   

            console.print($|Character {char.quoted()}:\
                           | Unicode codepoint={char.codepoint},\
                           | ASCII={char.ascii},\
                           | UTF8 bytes={char.utf8()},\
                           | char from codepoint={fromCodePoint.quoted()}
                         );
            }
        }
    }


PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"
Task: Character codes






PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"


Python: print ord('a') 
print chr(97)
Task: Character codes






PHP: echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"



VB: TextWindow.WriteLine("The ascii code for 
TextWindow.WriteLine("The character for
Task: Unique characters

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

char *uniques(char *str[], char *buf) {
    static unsigned counts[256];
    unsigned i;
    char *s, *o = buf;
    memset(counts, 0, 256 * sizeof(unsigned));
    
    for (; *str; str++)
        for (s = *str; *s; s++)
            counts[(unsigned) *s]++;
    
    for (i=0; i<256; i++)
        if (counts[i] == 1)
            *o++ = (char) i;
    
    *o = '\0';
    return buf;
}

int main() {
    char buf[256];
    char *strings[] = {
        "133252abcdeeffd",
        "a6789798st",
        "yxcdfgxcyz",
        NULL
    };
    
    printf("%s\n", uniques(strings, buf));
    return 0;
}



C#: #include <iostream>
#include <map>

int main() {
    const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"};
    std::map<char, int> count;
    for (const char* str : strings) {
        for (; *str; ++str)
            ++count[*str];
    }
    for (const auto& p : count) {
        if (p.second == 1)
            std::cout << p.first;
    }
    std::cout << '\n';
}
Task: Unique characters

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

char *uniques(char *str[], char *buf) {
    static unsigned counts[256];
    unsigned i;
    char *s, *o = buf;
    memset(counts, 0, 256 * sizeof(unsigned));
    
    for (; *str; str++)
        for (s = *str; *s; s++)
            counts[(unsigned) *s]++;
    
    for (i=0; i<256; i++)
        if (counts[i] == 1)
            *o++ = (char) i;
    
    *o = '\0';
    return buf;
}

int main() {
    char buf[256];
    char *strings[] = {
        "133252abcdeeffd",
        "a6789798st",
        "yxcdfgxcyz",
        NULL
    };
    
    printf("%s\n", uniques(strings, buf));
    return 0;
}







Python: 

from itertools import chain, groupby



def uniques(xs):
    
    return [
        h for h, (_, *tail) in
        groupby(sorted(chain(*xs)))
        if not tail
    ]




def main():
    
    print(
        uniques([
            "133252abcdeeffd",
            "a6789798st",
            "yxcdfgxcyz"
        ])
    )



if __name__ == '__main__':
    main()
Task: Unique characters


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

int main() {
    const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"};
    std::map<char, int> count;
    for (const char* str : strings) {
        for (; *str; ++str)
            ++count[*str];
    }
    for (const auto& p : count) {
        if (p.second == 1)
            std::cout << p.first;
    }
    std::cout << '\n';
}



Go: package main

import (
    "fmt"
    "sort"
)

func main() {
    strings := []string{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
    m := make(map[rune]int)
    for _, s := range strings {
        for _, c := range s {
            m[c]++
        }
    }
    var chars []rune
    for k, v := range m {
        if v == 1 {
            chars = append(chars, k)
        }
    }
    sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
    fmt.Println(string(chars))
}
Task: Unique characters


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

int main() {
    const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"};
    std::map<char, int> count;
    for (const char* str : strings) {
        for (; *str; ++str)
            ++count[*str];
    }
    for (const auto& p : count) {
        if (p.second == 1)
            std::cout << p.first;
    }
    std::cout << '\n';
}






Python: 

from itertools import chain, groupby



def uniques(xs):
    
    return [
        h for h, (_, *tail) in
        groupby(sorted(chain(*xs)))
        if not tail
    ]




def main():
    
    print(
        uniques([
            "133252abcdeeffd",
            "a6789798st",
            "yxcdfgxcyz"
        ])
    )



if __name__ == '__main__':
    main()
Task: Unique characters




Go: package main

import (
    "fmt"
    "sort"
)

func main() {
    strings := []string{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
    m := make(map[rune]int)
    for _, s := range strings {
        for _, c := range s {
            m[c]++
        }
    }
    var chars []rune
    for k, v := range m {
        if v == 1 {
            chars = append(chars, k)
        }
    }
    sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
    fmt.Println(string(chars))
}




Python: 

from itertools import chain, groupby



def uniques(xs):
    
    return [
        h for h, (_, *tail) in
        groupby(sorted(chain(*xs)))
        if not tail
    ]




def main():
    
    print(
        uniques([
            "133252abcdeeffd",
            "a6789798st",
            "yxcdfgxcyz"
        ])
    )



if __name__ == '__main__':
    main()
Task: Unique characters

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

char *uniques(char *str[], char *buf) {
    static unsigned counts[256];
    unsigned i;
    char *s, *o = buf;
    memset(counts, 0, 256 * sizeof(unsigned));
    
    for (; *str; str++)
        for (s = *str; *s; s++)
            counts[(unsigned) *s]++;
    
    for (i=0; i<256; i++)
        if (counts[i] == 1)
            *o++ = (char) i;
    
    *o = '\0';
    return buf;
}

int main() {
    char buf[256];
    char *strings[] = {
        "133252abcdeeffd",
        "a6789798st",
        "yxcdfgxcyz",
        NULL
    };
    
    printf("%s\n", uniques(strings, buf));
    return 0;
}


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

int main() {
    const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"};
    std::map<char, int> count;
    for (const char* str : strings) {
        for (; *str; ++str)
            ++count[*str];
    }
    for (const auto& p : count) {
        if (p.second == 1)
            std::cout << p.first;
    }
    std::cout << '\n';
}
Task: Unique characters

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

char *uniques(char *str[], char *buf) {
    static unsigned counts[256];
    unsigned i;
    char *s, *o = buf;
    memset(counts, 0, 256 * sizeof(unsigned));
    
    for (; *str; str++)
        for (s = *str; *s; s++)
            counts[(unsigned) *s]++;
    
    for (i=0; i<256; i++)
        if (counts[i] == 1)
            *o++ = (char) i;
    
    *o = '\0';
    return buf;
}

int main() {
    char buf[256];
    char *strings[] = {
        "133252abcdeeffd",
        "a6789798st",
        "yxcdfgxcyz",
        NULL
    };
    
    printf("%s\n", uniques(strings, buf));
    return 0;
}




Go: package main

import (
    "fmt"
    "sort"
)

func main() {
    strings := []string{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
    m := make(map[rune]int)
    for _, s := range strings {
        for _, c := range s {
            m[c]++
        }
    }
    var chars []rune
    for k, v := range m {
        if v == 1 {
            chars = append(chars, k)
        }
    }
    sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
    fmt.Println(string(chars))
}
Task: Chowla numbers

C: #include <stdio.h>

unsigned chowla(const unsigned n) {
  unsigned sum = 0;
  for (unsigned i = 2, j; i * i <= n; i ++) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
  return sum;
}

int main(int argc, char const *argv[]) {
  unsigned a;
  for (unsigned n = 1; n < 38; n ++) printf("chowla(%u) = %u\n", n, chowla(n));

  unsigned n, count = 0, power = 100;
  for (n = 2; n < 10000001; n ++) {
    if (chowla(n) == 0) count ++;
    if (n % power == 0) printf("There is %u primes < %u\n", count, power), power *= 10;
  }

  count = 0;
  unsigned limit = 350000000;
  unsigned k = 2, kk = 3, p;
  for ( ; ; ) {
    if ((p = k * kk) > limit) break;
    if (chowla(p) == p - 1) {
      printf("%d is a perfect number\n", p);
      count ++;
    }
    k = kk + 1; kk += k;
  }
  printf("There are %u perfect numbers < %u\n", count, limit);
  return 0;
}



C#: using System;

namespace chowla_cs
{
    class Program
    {
        static int chowla(int n)
        {
            int sum = 0;
            for (int i = 2, j; i * i <= n; i++)
                if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
            return sum;
        }

        static bool[] sieve(int limit)
        {
            
            
            bool[] c = new bool[limit];
            for (int i = 3; i * 3 < limit; i += 2)
                if (!c[i] && (chowla(i) == 0))
                    for (int j = 3 * i; j < limit; j += 2 * i)
                        c[j] = true;
            return c;
        }

        static void Main(string[] args)
        {
            for (int i = 1; i <= 37; i++)
                Console.WriteLine("chowla({0}) = {1}", i, chowla(i));
            int count = 1, limit = (int)(1e7), power = 100;
            bool[] c = sieve(limit);
            for (int i = 3; i < limit; i += 2)
            {
                if (!c[i]) count++;
                if (i == power - 1)
                {
                    Console.WriteLine("Count of primes up to {0,10:n0} = {1:n0}", power, count);
                    power *= 10;
                }
            }

            count = 0; limit = 35000000;
            int k = 2, kk = 3, p;
            for (int i = 2; ; i++)
            {
                if ((p = k * kk) > limit) break;
                if (chowla(p) == p - 1)
                {
                    Console.WriteLine("{0,10:n0} is a number that is perfect", p);
                    count++;
                }
                k = kk + 1; kk += k;
            }
            Console.WriteLine("There are {0} perfect numbers <= 35,000,000", count);
            if (System.Diagnostics.Debugger.IsAttached) Console.ReadKey();
        }
    }
}
Task: Chowla numbers

C: #include <stdio.h>

unsigned chowla(const unsigned n) {
  unsigned sum = 0;
  for (unsigned i = 2, j; i * i <= n; i ++) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
  return sum;
}

int main(int argc, char const *argv[]) {
  unsigned a;
  for (unsigned n = 1; n < 38; n ++) printf("chowla(%u) = %u\n", n, chowla(n));

  unsigned n, count = 0, power = 100;
  for (n = 2; n < 10000001; n ++) {
    if (chowla(n) == 0) count ++;
    if (n % power == 0) printf("There is %u primes < %u\n", count, power), power *= 10;
  }

  count = 0;
  unsigned limit = 350000000;
  unsigned k = 2, kk = 3, p;
  for ( ; ; ) {
    if ((p = k * kk) > limit) break;
    if (chowla(p) == p - 1) {
      printf("%d is a perfect number\n", p);
      count ++;
    }
    k = kk + 1; kk += k;
  }
  printf("There are %u perfect numbers < %u\n", count, limit);
  return 0;
}


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

using namespace std;

int chowla(int n)
{
	int sum = 0;
	for (int i = 2, j; i * i <= n; i++)
		if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
	return sum;
}

vector<bool> sieve(int limit)
{
	
	
	vector<bool> c(limit);
	for (int i = 3; i * 3 < limit; i += 2)
		if (!c[i] && (chowla(i) == 0))
			for (int j = 3 * i; j < limit; j += 2 * i)
				c[j] = true;
	return c;
}

int main()
{
	cout.imbue(locale(""));
	for (int i = 1; i <= 37; i++)
		cout << "chowla(" << i << ") = " << chowla(i) << "\n";
	int count = 1, limit = (int)(1e7), power = 100;
	vector<bool> c = sieve(limit);
	for (int i = 3; i < limit; i += 2)
	{
		if (!c[i]) count++;
		if (i == power - 1)
		{
			cout << "Count of primes up to " << power << " = "<< count <<"\n";
			power *= 10;
		}
	}

	count = 0; limit = 35000000;
	int k = 2, kk = 3, p;
	for (int i = 2; ; i++)
	{
		if ((p = k * kk) > limit) break;
		if (chowla(p) == p - 1)
		{
			cout << p << " is a number that is perfect\n";
			count++;
		}
		k = kk + 1; kk += k;
	}
	cout << "There are " << count << " perfect numbers <= 35,000,000\n";
	return 0;
}
Task: Chowla numbers

C: #include <stdio.h>

unsigned chowla(const unsigned n) {
  unsigned sum = 0;
  for (unsigned i = 2, j; i * i <= n; i ++) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
  return sum;
}

int main(int argc, char const *argv[]) {
  unsigned a;
  for (unsigned n = 1; n < 38; n ++) printf("chowla(%u) = %u\n", n, chowla(n));

  unsigned n, count = 0, power = 100;
  for (n = 2; n < 10000001; n ++) {
    if (chowla(n) == 0) count ++;
    if (n % power == 0) printf("There is %u primes < %u\n", count, power), power *= 10;
  }

  count = 0;
  unsigned limit = 350000000;
  unsigned k = 2, kk = 3, p;
  for ( ; ; ) {
    if ((p = k * kk) > limit) break;
    if (chowla(p) == p - 1) {
      printf("%d is a perfect number\n", p);
      count ++;
    }
    k = kk + 1; kk += k;
  }
  printf("There are %u perfect numbers < %u\n", count, limit);
  return 0;
}




Go: package main

import "fmt"

func chowla(n int) int {
    if n < 1 {
        panic("argument must be a positive integer")
    }
    sum := 0
    for i := 2; i*i <= n; i++ {
        if n%i == 0 {
            j := n / i
            if i == j {
                sum += i
            } else {
                sum += i + j
            }
        }
    }
    return sum
}

func sieve(limit int) []bool {
    
    
    c := make([]bool, limit)
    for i := 3; i*3 < limit; i += 2 {
        if !c[i] && chowla(i) == 0 {
            for j := 3 * i; j < limit; j += 2 * i {
                c[j] = true
            }
        }
    }
    return c
}

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

func main() {
    for i := 1; i <= 37; i++ {
        fmt.Printf("chowla(%2d) = %d\n", i, chowla(i))
    }
    fmt.Println()

    count := 1
    limit := int(1e7)
    c := sieve(limit)
    power := 100
    for i := 3; i < limit; i += 2 {
        if !c[i] {
            count++
        }
        if i == power-1 {
            fmt.Printf("Count of primes up to %-10s = %s\n", commatize(power), commatize(count))
            power *= 10
        }
    }

    fmt.Println()
    count = 0
    limit = 35000000
    for i := uint(2); ; i++ {
        p := 1 << (i - 1) * (1<<i - 1) 
        if p > limit {
            break
        }
        if chowla(p) == p-1 {
            fmt.Printf("%s is a perfect number\n", commatize(p))
            count++
        }
    }
    fmt.Println("There are", count, "perfect numbers <= 35,000,000")
}