WeixiangYan/CodeTransOcean huggingface dataset:
Task: ABC words



C#: class Program {
    static void Main(string[] args) { int bi, i = 0; string chars = args.Length < 1 ? "abc" : args[0];
        foreach (var item in System.IO.File.ReadAllLines("unixdict.txt")) {
            int ai = -1; foreach (var ch in chars)
                if ((bi = item.IndexOf(ch)) > ai) ai = bi; else goto skip;
            System.Console.Write("{0,3} {1,-18} {2}", ++i, item, i % 5 == 0 ? "\n" : "");
        skip: ; } }
}



Java: import java.io.BufferedReader;
import java.io.FileReader;

public class AbcWords {
    public static void main(String[] args) {
        String fileName = "unixdict.txt";
        String chars = "abc";
        for (int i = 0; i + 1 < args.length
                && args[i].length() > 1
                && args[i].charAt(0) == '-'; ++i) {
            switch (args[i].charAt(1)) {
            case 'f':
                fileName = args[++i];
                break;
            case 'c':
                chars = args[++i];
                break;
            }
        }
        
        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
            String line;
            int n = 0;
            while ((line = reader.readLine()) != null) {
                if (match(line, chars)) {
                    ++n;
                    System.out.printf("%3d: %-20s", n, line);
                    if (n % 3 == 0)
                        System.out.println();
                }
            }
            if (n > 0 && n % 3 != 0)
                System.out.println();
        } catch (Exception e)  {
            e.printStackTrace();
        }
    }

    
    
    private static boolean match(String word, String chars) {
        int length = chars.length();
        boolean[] seen = new boolean[length];
        int wordLength = word.length();
        for (int w = 0; w < wordLength; ++w) {
            char ch = word.charAt(w);
            int index = -1;
            for (int c = 0; c < length; ++c) {
                if (ch == chars.charAt(c) && !seen[c]) {
                    index = c;
                    break;
                }
            }
            if (index == -1)
                continue;
            if (index + 1 == length)
                return index == 0 ? true : seen[index - 1];
            if (index > 0 && !seen[index - 1])
                return false;
            seen[index] = true;
        }
        return false;
    }
}
Task: ABC words




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    count := 0
    fmt.Println("Based on first occurrences only, the ABC words in", wordList, "are:")
    for _, bword := range bwords {
        a := bytes.IndexRune(bword, 'a')
        b := bytes.IndexRune(bword, 'b')
        c := bytes.IndexRune(bword, 'c')
        if a >= 0 && b > a && c > b {
            count++
            fmt.Printf("%2d: %s\n", count, string(bword))
        }
    }
}


Java: import java.io.BufferedReader;
import java.io.FileReader;

public class AbcWords {
    public static void main(String[] args) {
        String fileName = "unixdict.txt";
        String chars = "abc";
        for (int i = 0; i + 1 < args.length
                && args[i].length() > 1
                && args[i].charAt(0) == '-'; ++i) {
            switch (args[i].charAt(1)) {
            case 'f':
                fileName = args[++i];
                break;
            case 'c':
                chars = args[++i];
                break;
            }
        }
        
        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
            String line;
            int n = 0;
            while ((line = reader.readLine()) != null) {
                if (match(line, chars)) {
                    ++n;
                    System.out.printf("%3d: %-20s", n, line);
                    if (n % 3 == 0)
                        System.out.println();
                }
            }
            if (n > 0 && n % 3 != 0)
                System.out.println();
        } catch (Exception e)  {
            e.printStackTrace();
        }
    }

    
    
    private static boolean match(String word, String chars) {
        int length = chars.length();
        boolean[] seen = new boolean[length];
        int wordLength = word.length();
        for (int w = 0; w < wordLength; ++w) {
            char ch = word.charAt(w);
            int index = -1;
            for (int c = 0; c < length; ++c) {
                if (ch == chars.charAt(c) && !seen[c]) {
                    index = c;
                    break;
                }
            }
            if (index == -1)
                continue;
            if (index + 1 == length)
                return index == 0 ? true : seen[index - 1];
            if (index > 0 && !seen[index - 1])
                return false;
            seen[index] = true;
        }
        return false;
    }
}
Task: ABC words





Java: import java.io.BufferedReader;
import java.io.FileReader;

public class AbcWords {
    public static void main(String[] args) {
        String fileName = "unixdict.txt";
        String chars = "abc";
        for (int i = 0; i + 1 < args.length
                && args[i].length() > 1
                && args[i].charAt(0) == '-'; ++i) {
            switch (args[i].charAt(1)) {
            case 'f':
                fileName = args[++i];
                break;
            case 'c':
                chars = args[++i];
                break;
            }
        }
        
        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
            String line;
            int n = 0;
            while ((line = reader.readLine()) != null) {
                if (match(line, chars)) {
                    ++n;
                    System.out.printf("%3d: %-20s", n, line);
                    if (n % 3 == 0)
                        System.out.println();
                }
            }
            if (n > 0 && n % 3 != 0)
                System.out.println();
        } catch (Exception e)  {
            e.printStackTrace();
        }
    }

    
    
    private static boolean match(String word, String chars) {
        int length = chars.length();
        boolean[] seen = new boolean[length];
        int wordLength = word.length();
        for (int w = 0; w < wordLength; ++w) {
            char ch = word.charAt(w);
            int index = -1;
            for (int c = 0; c < length; ++c) {
                if (ch == chars.charAt(c) && !seen[c]) {
                    index = c;
                    break;
                }
            }
            if (index == -1)
                continue;
            if (index + 1 == length)
                return index == 0 ? true : seen[index - 1];
            if (index > 0 && !seen[index - 1])
                return false;
            seen[index] = true;
        }
        return false;
    }
}



Python: python -c '
import sys
for ln in sys.stdin:
    if "a" in ln and ln.find("a") < ln.find("b") < ln.find("c"):
        print(ln.rstrip())
' < unixdict.txt
Task: ABC words




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    count := 0
    fmt.Println("Based on first occurrences only, the ABC words in", wordList, "are:")
    for _, bword := range bwords {
        a := bytes.IndexRune(bword, 'a')
        b := bytes.IndexRune(bword, 'b')
        c := bytes.IndexRune(bword, 'c')
        if a >= 0 && b > a && c > b {
            count++
            fmt.Printf("%2d: %s\n", count, string(bword))
        }
    }
}




Python: python -c '
import sys
for ln in sys.stdin:
    if "a" in ln and ln.find("a") < ln.find("b") < ln.find("c"):
        print(ln.rstrip())
' < unixdict.txt
Task: ABC words

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

int match(const char *word) {
    const char *a = strchr(word, 'a');
    const char *b = strchr(word, 'b');
    const char *c = strchr(word, 'c');
    return a && b && c && a<b && b<c;
}

int main() {
    char word[80];
    FILE *file = fopen("unixdict.txt", "r");
    if (!file) {
        fprintf(stderr, "Cannot open unixdict.txt");
        return -1;
    }
    
    while (!feof(file)) {
        fgets(word, sizeof(word), file);
        if(match(word)) printf("%s", word);
    }
    return 0;
}


C++: #include <cstdlib>
#include <fstream>
#include <iostream>

bool is_abc_word(const std::string& word) {
    bool a = false;
    bool b = false;
    for (char ch : word) {
        switch (ch) {
        case 'a':
            if (!a)
                a = true;
            break;
        case 'b':
            if (!b) {
                
                if (!a)
                    return false;
                b = true;
            }
            break;
        case 'c':
            
            return b;
        }
    }
    return false;
}

int main(int argc, char** argv) {
    const char* filename(argc < 2 ? "unixdict.txt" : argv[1]);
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string word;
    int n = 1;
    while (getline(in, word)) {
        if (is_abc_word(word))
            std::cout << n++ << ": " << word << '\n';
    }
    return EXIT_SUCCESS;
}
Task: ABC words



C#: class Program {
    static void Main(string[] args) { int bi, i = 0; string chars = args.Length < 1 ? "abc" : args[0];
        foreach (var item in System.IO.File.ReadAllLines("unixdict.txt")) {
            int ai = -1; foreach (var ch in chars)
                if ((bi = item.IndexOf(ch)) > ai) ai = bi; else goto skip;
            System.Console.Write("{0,3} {1,-18} {2}", ++i, item, i % 5 == 0 ? "\n" : "");
        skip: ; } }
}





Python: python -c '
import sys
for ln in sys.stdin:
    if "a" in ln and ln.find("a") < ln.find("b") < ln.find("c"):
        print(ln.rstrip())
' < unixdict.txt
Task: ABC words

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

int match(const char *word) {
    const char *a = strchr(word, 'a');
    const char *b = strchr(word, 'b');
    const char *c = strchr(word, 'c');
    return a && b && c && a<b && b<c;
}

int main() {
    char word[80];
    FILE *file = fopen("unixdict.txt", "r");
    if (!file) {
        fprintf(stderr, "Cannot open unixdict.txt");
        return -1;
    }
    
    while (!feof(file)) {
        fgets(word, sizeof(word), file);
        if(match(word)) printf("%s", word);
    }
    return 0;
}







Python: python -c '
import sys
for ln in sys.stdin:
    if "a" in ln and ln.find("a") < ln.find("b") < ln.find("c"):
        print(ln.rstrip())
' < unixdict.txt
Task: ABC words


C++: #include <cstdlib>
#include <fstream>
#include <iostream>

bool is_abc_word(const std::string& word) {
    bool a = false;
    bool b = false;
    for (char ch : word) {
        switch (ch) {
        case 'a':
            if (!a)
                a = true;
            break;
        case 'b':
            if (!b) {
                
                if (!a)
                    return false;
                b = true;
            }
            break;
        case 'c':
            
            return b;
        }
    }
    return false;
}

int main(int argc, char** argv) {
    const char* filename(argc < 2 ? "unixdict.txt" : argv[1]);
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string word;
    int n = 1;
    while (getline(in, word)) {
        if (is_abc_word(word))
            std::cout << n++ << ": " << word << '\n';
    }
    return EXIT_SUCCESS;
}


C#: class Program {
    static void Main(string[] args) { int bi, i = 0; string chars = args.Length < 1 ? "abc" : args[0];
        foreach (var item in System.IO.File.ReadAllLines("unixdict.txt")) {
            int ai = -1; foreach (var ch in chars)
                if ((bi = item.IndexOf(ch)) > ai) ai = bi; else goto skip;
            System.Console.Write("{0,3} {1,-18} {2}", ++i, item, i % 5 == 0 ? "\n" : "");
        skip: ; } }
}
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}




Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}







Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}


C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}



Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}
Task: Terminal control_Hiding the cursor



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}


Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}
Task: Terminal control_Hiding the cursor



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}





Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor




Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}




Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}






Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}






PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);
Task: Terminal control_Hiding the cursor



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}




PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}





PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);
Task: Terminal control_Hiding the cursor




Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}



PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);
Task: Terminal control_Hiding the cursor






PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);


Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor






PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);



VB: Locate , , 0    

Sleep 500       

Locate , , 1    

Sleep
Task: Generate lower case ASCII alphabet

C: #include <stdlib.h>

#define N 26

int main() {
    unsigned char lower[N];

    for (size_t i = 0; i < N; i++) {
        lower[i] = i + 'a';
    }

    return EXIT_SUCCESS;
}


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

int main() {
    std::string lower(26,' ');

    std::iota(lower.begin(), lower.end(), 'a');
}
Task: Generate lower case ASCII alphabet

C: #include <stdlib.h>

#define N 26

int main() {
    unsigned char lower[N];

    for (size_t i = 0; i < N; i++) {
        lower[i] = i + 'a';
    }

    return EXIT_SUCCESS;
}





Java: public class LowerAscii {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(26);
        for (char ch = 'a'; ch <= 'z'; ch++)
            sb.append(ch);
        System.out.printf("lower ascii: %s, length: %s", sb, sb.length());
    }
}
Task: Generate lower case ASCII alphabet

C: #include <stdlib.h>

#define N 26

int main() {
    unsigned char lower[N];

    for (size_t i = 0; i < N; i++) {
        lower[i] = i + 'a';
    }

    return EXIT_SUCCESS;
}







Python: 
from string import ascii_lowercase


lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]
Task: Generate lower case ASCII alphabet


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

int main() {
    std::string lower(26,' ');

    std::iota(lower.begin(), lower.end(), 'a');
}




Java: public class LowerAscii {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(26);
        for (char ch = 'a'; ch <= 'z'; ch++)
            sb.append(ch);
        System.out.printf("lower ascii: %s, length: %s", sb, sb.length());
    }
}
Task: Generate lower case ASCII alphabet


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

int main() {
    std::string lower(26,' ');

    std::iota(lower.begin(), lower.end(), 'a');
}






Python: 
from string import ascii_lowercase


lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]
Task: Generate lower case ASCII alphabet




Go: func loweralpha() string {
	p := make([]byte, 26)
	for i := range p {
		p[i] = 'a' + byte(i)
	}
	return string(p)
}


Java: public class LowerAscii {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(26);
        for (char ch = 'a'; ch <= 'z'; ch++)
            sb.append(ch);
        System.out.printf("lower ascii: %s, length: %s", sb, sb.length());
    }
}
Task: Generate lower case ASCII alphabet





Java: public class LowerAscii {

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(26);
        for (char ch = 'a'; ch <= 'z'; ch++)
            sb.append(ch);
        System.out.printf("lower ascii: %s, length: %s", sb, sb.length());
    }
}



Python: 
from string import ascii_lowercase


lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]