WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sort numbers lexicographically




Go: package main

import (
    "fmt"
    "sort"
    "strconv"
)

func lexOrder(n int) []int {
    first, last, k := 1, n, n
    if n < 1 {
        first, last, k = n, 1, 2-n
    }
    strs := make([]string, k)
    for i := first; i <= last; i++ {
        strs[i-first] = strconv.Itoa(i)
    }
    sort.Strings(strs)
    ints := make([]int, k)
    for i := 0; i < k; i++ {
        ints[i], _ = strconv.Atoi(strs[i])
    }
    return ints
}

func main() {
    fmt.Println("In lexicographical order:\n")
    for _, n := range []int{0, 5, 13, 21, -22} {
        fmt.Printf("%3d: %v\n", n, lexOrder(n))
    }
}








Ada: WITH Ada.Containers.Generic_Array_Sort, Ada.Text_IO;
USE  Ada.Text_IO;
PROCEDURE Main IS
   TYPE Natural_Array IS ARRAY (Positive RANGE <>) OF Natural;
   FUNCTION Less (L, R : Natural) RETURN Boolean IS (L'Img < R'Img);
   PROCEDURE Sort_Naturals IS NEW Ada.Containers.Generic_Array_Sort
     (Positive, Natural, Natural_Array, Less);
   PROCEDURE Show (Last : Natural) IS
      A : Natural_Array (1 .. Last);
   BEGIN
      FOR I IN A'Range LOOP A (I) := I; END LOOP;
      Sort_Naturals (A);
      FOR I IN  A'Range LOOP Put (A (I)'Img); END LOOP;
      New_Line;
   END Show;
BEGIN
   Show (13);
   Show (21);
END Main;
Task: Sort numbers lexicographically





Java: import java.util.List;
import java.util.stream.*;

public class LexicographicalNumbers {

    static List<Integer> lexOrder(int n) {
        int first = 1, last = n;
        if (n < 1) {
            first = n;
            last = 1;
        }
        return IntStream.rangeClosed(first, last)
                        .mapToObj(Integer::toString)
                        .sorted()
                        .map(Integer::valueOf)
                        .collect(Collectors.toList());
    }

    public static void main(String[] args) {
        System.out.println("In lexicographical order:\n");
        int[] ints = {0, 5, 13, 21, -22};
        for (int n : ints) {
           System.out.printf("%3d: %s\n", n, lexOrder(n));
        }
    }
}







Ada: WITH Ada.Containers.Generic_Array_Sort, Ada.Text_IO;
USE  Ada.Text_IO;
PROCEDURE Main IS
   TYPE Natural_Array IS ARRAY (Positive RANGE <>) OF Natural;
   FUNCTION Less (L, R : Natural) RETURN Boolean IS (L'Img < R'Img);
   PROCEDURE Sort_Naturals IS NEW Ada.Containers.Generic_Array_Sort
     (Positive, Natural, Natural_Array, Less);
   PROCEDURE Show (Last : Natural) IS
      A : Natural_Array (1 .. Last);
   BEGIN
      FOR I IN A'Range LOOP A (I) := I; END LOOP;
      Sort_Naturals (A);
      FOR I IN  A'Range LOOP Put (A (I)'Img); END LOOP;
      New_Line;
   END Show;
BEGIN
   Show (13);
   Show (21);
END Main;
Task: Sort numbers lexicographically







Python: n=13
print(sorted(range(1,n+1), key=str))





Ada: WITH Ada.Containers.Generic_Array_Sort, Ada.Text_IO;
USE  Ada.Text_IO;
PROCEDURE Main IS
   TYPE Natural_Array IS ARRAY (Positive RANGE <>) OF Natural;
   FUNCTION Less (L, R : Natural) RETURN Boolean IS (L'Img < R'Img);
   PROCEDURE Sort_Naturals IS NEW Ada.Containers.Generic_Array_Sort
     (Positive, Natural, Natural_Array, Less);
   PROCEDURE Show (Last : Natural) IS
      A : Natural_Array (1 .. Last);
   BEGIN
      FOR I IN A'Range LOOP A (I) := I; END LOOP;
      Sort_Naturals (A);
      FOR I IN  A'Range LOOP Put (A (I)'Img); END LOOP;
      New_Line;
   END Show;
BEGIN
   Show (13);
   Show (21);
END Main;
Task: Sort numbers lexicographically








VB: Public Function sortlexicographically(N As Integer)
    Dim arrList As Object
    Set arrList = CreateObject("System.Collections.ArrayList")
    For i = 1 To N
        arrList.Add CStr(i)
    Next i
    arrList.Sort
    Dim item As Variant
    For Each item In arrList
        Debug.Print item & ", ";
    Next
End Function

Public Sub main()
    Call sortlexicographically(13)
End Sub




Ada: WITH Ada.Containers.Generic_Array_Sort, Ada.Text_IO;
USE  Ada.Text_IO;
PROCEDURE Main IS
   TYPE Natural_Array IS ARRAY (Positive RANGE <>) OF Natural;
   FUNCTION Less (L, R : Natural) RETURN Boolean IS (L'Img < R'Img);
   PROCEDURE Sort_Naturals IS NEW Ada.Containers.Generic_Array_Sort
     (Positive, Natural, Natural_Array, Less);
   PROCEDURE Show (Last : Natural) IS
      A : Natural_Array (1 .. Last);
   BEGIN
      FOR I IN A'Range LOOP A (I) := I; END LOOP;
      Sort_Naturals (A);
      FOR I IN  A'Range LOOP Put (A (I)'Img); END LOOP;
      New_Line;
   END Show;
BEGIN
   Show (13);
   Show (21);
END Main;
Task: Sort numbers lexicographically

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

int compareStrings(const void *a, const void *b) {
    const char **aa = (const char **)a;
    const char **bb = (const char **)b;
    return strcmp(*aa, *bb);
}

void lexOrder(int n, int *ints) {
    char **strs;
    int i, first = 1, last = n, k = n, len;
    if (n < 1) {
        first = n; last = 1; k = 2 - n;
    } 
    strs = malloc(k * sizeof(char *));
    for (i = first; i <= last; ++i) {
        if (i >= 1) len = (int)log10(i) + 2;
        else if (i == 0) len = 2;
        else len = (int)log10(-i) + 3; 
        strs[i-first] = malloc(len);
        sprintf(strs[i-first], "%d", i);
    }
    qsort(strs, k, sizeof(char *), compareStrings);
    for (i = 0; i < k; ++i) {
        ints[i] = atoi(strs[i]);
        free(strs[i]);
    }
    free(strs);
}

int main() {
    int i, j, k, n,  *ints;
    int numbers[5] = {0, 5, 13, 21, -22};
    printf("In lexicographical order:\n\n");
    for (i = 0; i < 5; ++i) {
        k = n = numbers[i];
        if (k < 1) k = 2 - k;
        ints = malloc(k * sizeof(int));
        lexOrder(n, ints);
        printf("%3d: [", n);
        for (j = 0; j < k; ++j) {
            printf("%d ", ints[j]);
        }
        printf("\b]\n");
        free(ints);
    }
    return 0;
}
Task: Sort numbers lexicographically



C#: using static System.Console;
using static System.Linq.Enumerable;

public class Program
{
    public static void Main() {
        foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
    }

    public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : Range(1, n)).OrderBy(i => i.ToString());
}
Task: Sort numbers lexicographically


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

void lexicographical_sort(std::vector<int>& numbers) {
    std::vector<std::string> strings(numbers.size());
    std::transform(numbers.begin(), numbers.end(), strings.begin(),
                   [](int i) { return std::to_string(i); });
    std::sort(strings.begin(), strings.end());
    std::transform(strings.begin(), strings.end(), numbers.begin(),
                   [](const std::string& s) { return std::stoi(s); });
}

std::vector<int> lexicographically_sorted_vector(int n) {
    std::vector<int> numbers(n >= 1 ? n : 2 - n);
    std::iota(numbers.begin(), numbers.end(), std::min(1, n));
    lexicographical_sort(numbers);
    return numbers;
}

template <typename T>
void print_vector(std::ostream& out, const std::vector<T>& v) {
    out << '[';
    if (!v.empty()) {
        auto i = v.begin();
        out << *i++;
        for (; i != v.end(); ++i)
            out << ',' << *i;
    }
    out << "]\n";
}

int main(int argc, char** argv) {
    for (int i : { 0, 5, 13, 21, -22 }) {
        std::cout << i << ": ";
        print_vector(std::cout, lexicographically_sorted_vector(i));
    }
    return 0;
}
Task: Sort numbers lexicographically





Java: import java.util.List;
import java.util.stream.*;

public class LexicographicalNumbers {

    static List<Integer> lexOrder(int n) {
        int first = 1, last = n;
        if (n < 1) {
            first = n;
            last = 1;
        }
        return IntStream.rangeClosed(first, last)
                        .mapToObj(Integer::toString)
                        .sorted()
                        .map(Integer::valueOf)
                        .collect(Collectors.toList());
    }

    public static void main(String[] args) {
        System.out.println("In lexicographical order:\n");
        int[] ints = {0, 5, 13, 21, -22};
        for (int n : ints) {
           System.out.printf("%3d: %s\n", n, lexOrder(n));
        }
    }
}
Task: Sort numbers lexicographically







Python: n=13
print(sorted(range(1,n+1), key=str))
Task: Sort numbers lexicographically








VB: Public Function sortlexicographically(N As Integer)
    Dim arrList As Object
    Set arrList = CreateObject("System.Collections.ArrayList")
    For i = 1 To N
        arrList.Add CStr(i)
    Next i
    arrList.Sort
    Dim item As Variant
    For Each item In arrList
        Debug.Print item & ", ";
    Next
End Function

Public Sub main()
    Call sortlexicographically(13)
End Sub
Task: Sort numbers lexicographically




Go: package main

import (
    "fmt"
    "sort"
    "strconv"
)

func lexOrder(n int) []int {
    first, last, k := 1, n, n
    if n < 1 {
        first, last, k = n, 1, 2-n
    }
    strs := make([]string, k)
    for i := first; i <= last; i++ {
        strs[i-first] = strconv.Itoa(i)
    }
    sort.Strings(strs)
    ints := make([]int, k)
    for i := 0; i < k; i++ {
        ints[i], _ = strconv.Atoi(strs[i])
    }
    return ints
}

func main() {
    fmt.Println("In lexicographical order:\n")
    for _, n := range []int{0, 5, 13, 21, -22} {
        fmt.Printf("%3d: %v\n", n, lexOrder(n))
    }
}
Task: Sort numbers lexicographically

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

int compareStrings(const void *a, const void *b) {
    const char **aa = (const char **)a;
    const char **bb = (const char **)b;
    return strcmp(*aa, *bb);
}

void lexOrder(int n, int *ints) {
    char **strs;
    int i, first = 1, last = n, k = n, len;
    if (n < 1) {
        first = n; last = 1; k = 2 - n;
    } 
    strs = malloc(k * sizeof(char *));
    for (i = first; i <= last; ++i) {
        if (i >= 1) len = (int)log10(i) + 2;
        else if (i == 0) len = 2;
        else len = (int)log10(-i) + 3; 
        strs[i-first] = malloc(len);
        sprintf(strs[i-first], "%d", i);
    }
    qsort(strs, k, sizeof(char *), compareStrings);
    for (i = 0; i < k; ++i) {
        ints[i] = atoi(strs[i]);
        free(strs[i]);
    }
    free(strs);
}

int main() {
    int i, j, k, n,  *ints;
    int numbers[5] = {0, 5, 13, 21, -22};
    printf("In lexicographical order:\n\n");
    for (i = 0; i < 5; ++i) {
        k = n = numbers[i];
        if (k < 1) k = 2 - k;
        ints = malloc(k * sizeof(int));
        lexOrder(n, ints);
        printf("%3d: [", n);
        for (j = 0; j < k; ++j) {
            printf("%d ", ints[j]);
        }
        printf("\b]\n");
        free(ints);
    }
    return 0;
}









COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically



C#: using static System.Console;
using static System.Linq.Enumerable;

public class Program
{
    public static void Main() {
        foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
    }

    public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : Range(1, n)).OrderBy(i => i.ToString());
}







COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically


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

void lexicographical_sort(std::vector<int>& numbers) {
    std::vector<std::string> strings(numbers.size());
    std::transform(numbers.begin(), numbers.end(), strings.begin(),
                   [](int i) { return std::to_string(i); });
    std::sort(strings.begin(), strings.end());
    std::transform(strings.begin(), strings.end(), numbers.begin(),
                   [](const std::string& s) { return std::stoi(s); });
}

std::vector<int> lexicographically_sorted_vector(int n) {
    std::vector<int> numbers(n >= 1 ? n : 2 - n);
    std::iota(numbers.begin(), numbers.end(), std::min(1, n));
    lexicographical_sort(numbers);
    return numbers;
}

template <typename T>
void print_vector(std::ostream& out, const std::vector<T>& v) {
    out << '[';
    if (!v.empty()) {
        auto i = v.begin();
        out << *i++;
        for (; i != v.end(); ++i)
            out << ',' << *i;
    }
    out << "]\n";
}

int main(int argc, char** argv) {
    for (int i : { 0, 5, 13, 21, -22 }) {
        std::cout << i << ": ";
        print_vector(std::cout, lexicographically_sorted_vector(i));
    }
    return 0;
}








COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically





Java: import java.util.List;
import java.util.stream.*;

public class LexicographicalNumbers {

    static List<Integer> lexOrder(int n) {
        int first = 1, last = n;
        if (n < 1) {
            first = n;
            last = 1;
        }
        return IntStream.rangeClosed(first, last)
                        .mapToObj(Integer::toString)
                        .sorted()
                        .map(Integer::valueOf)
                        .collect(Collectors.toList());
    }

    public static void main(String[] args) {
        System.out.println("In lexicographical order:\n");
        int[] ints = {0, 5, 13, 21, -22};
        for (int n : ints) {
           System.out.printf("%3d: %s\n", n, lexOrder(n));
        }
    }
}





COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically







Python: n=13
print(sorted(range(1,n+1), key=str))



COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically








VB: Public Function sortlexicographically(N As Integer)
    Dim arrList As Object
    Set arrList = CreateObject("System.Collections.ArrayList")
    For i = 1 To N
        arrList.Add CStr(i)
    Next i
    arrList.Sort
    Dim item As Variant
    For Each item In arrList
        Debug.Print item & ", ";
    Next
End Function

Public Sub main()
    Call sortlexicographically(13)
End Sub


COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Sort numbers lexicographically




Go: package main

import (
    "fmt"
    "sort"
    "strconv"
)

func lexOrder(n int) []int {
    first, last, k := 1, n, n
    if n < 1 {
        first, last, k = n, 1, 2-n
    }
    strs := make([]string, k)
    for i := first; i <= last; i++ {
        strs[i-first] = strconv.Itoa(i)
    }
    sort.Strings(strs)
    ints := make([]int, k)
    for i := 0; i < k; i++ {
        ints[i], _ = strconv.Atoi(strs[i])
    }
    return ints
}

func main() {
    fmt.Println("In lexicographical order:\n")
    for _, n := range []int{0, 5, 13, 21, -22} {
        fmt.Printf("%3d: %v\n", n, lexOrder(n))
    }
}






COBOL:        identification division.
       program-id. LexicographicalNumbers.

       data division.
       working-storage section.
       78  MAX-NUMBERS            value 21.
       77  i                      pic 9(2).
       77  edited-number          pic z(2).
       
       01  lex-table.
           05 table-itms occurs MAX-NUMBERS.
              10 number-lex       pic x(2).

       procedure division.
       main.
      
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              move i to edited-number
              move edited-number to number-lex(i)
              call "C$JUSTIFY" using number-lex(i), "Left"
           end-perform

      
           sort table-itms ascending number-lex

      
           display "[" no advancing
           perform varying i from 1 by 1 until i > MAX-NUMBERS
              display function trim(number-lex(i)) no advancing
              if i < MAX-NUMBERS
                 display ", " no advancing
              end-if
           end-perform
           display "]"
           stop run
           .
Task: Remove vowels from a string



C#: static string remove_vowels(string value)
{
    var stripped = from c in value.ToCharArray()
                   where !"aeiouAEIOU".Contains(c)
                   select c;

    return new string(stripped.ToArray());
}

static void test(string value)
{
    Console.WriteLine("Input:  " + value);
    Console.WriteLine("Output: " + remove_vowels(value));
}

static void Main(string[] args)
{
    test("CSharp Programming Language");
}









Ada: with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Main is
   subtype Vowel is Character with
        Static_Predicate => Vowel in 'A' | 'E' | 'I' | 'O' | 'U' | 'a' | 'e' |
            'i' | 'o' | 'u';

   function Remove_Vowels (S : in String) return String is
      Temp : Unbounded_String;
   begin
      for C of S loop
         if C not in Vowel then
            Append (Source => Temp, New_Item => C);
         end if;
      end loop;
      return To_String (Temp);
   end Remove_Vowels;

   S1  : String := "The Quick Brown Fox Jumped Over the Lazy Dog's Back";
   S2  : String := "DON'T SCREAM AT ME!!";
   NV1 : String := Remove_Vowels (S1);
   NV2 : String := Remove_Vowels (S2);
begin
   Put_Line (S1);
   Put_Line (NV1);
   New_Line;
   Put_Line (S2);
   Put_Line (NV2);
end Main;