kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Compare a list of strings
C#: public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
    strings.Count < 2 ? (true, true) :
    (
        strings.Distinct().Count() < 2,
        Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
    );

Go: package cmp

func AllEqual(strings []string) bool {
	for _, s := range strings {
		if s != strings[0] {
			return false
		}
	}
	return true
}

func AllLessThan(strings []string) bool {
	for i := 1; i < len(strings); i++ {
		if !(strings[i - 1] < s) {
			return false
		}
	}
	return true
}
Task: Compare a list of strings
C#: public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
    strings.Count < 2 ? (true, true) :
    (
        strings.Distinct().Count() < 2,
        Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
    );

Python: all(a == nexta for a, nexta in zip(strings, strings[1:])) 
all(a < nexta for a, nexta in zip(strings, strings[1:])) 

len(set(strings)) == 1  
sorted(strings, reverse=True) == strings
Task: Compare a list of strings
C#: public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
    strings.Count < 2 ? (true, true) :
    (
        strings.Distinct().Count() < 2,
        Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
    );

VB: Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean

    On Error Resume Next
    If UBound(myList) > 0 Then
        If Err.Number > 0 Then
            IsEqualOrAscending = "Error " & Err.Number & " : Empty array"
            On Error GoTo 0
            Exit Function
        Else
            For i = 1 To UBound(myList)
                If myList(i) <> myList(i - 1) Then boolEqual = True
                If myList(i) <= myList(i - 1) Then boolAsc = True
            Next
        End If
    End If
    IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
Task: Compare a list of strings
Go: package cmp

func AllEqual(strings []string) bool {
	for _, s := range strings {
		if s != strings[0] {
			return false
		}
	}
	return true
}

func AllLessThan(strings []string) bool {
	for i := 1; i < len(strings); i++ {
		if !(strings[i - 1] < s) {
			return false
		}
	}
	return true
}

Java: import java.util.Arrays;

public class CompareListOfStrings {

    public static void main(String[] args) {
        String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
        for (String[] a : arr) {
            System.out.println(Arrays.toString(a));
            System.out.println(Arrays.stream(a).distinct().count() < 2);
            System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
        }
    }
}
Task: Compare a list of strings
Java: import java.util.Arrays;

public class CompareListOfStrings {

    public static void main(String[] args) {
        String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
        for (String[] a : arr) {
            System.out.println(Arrays.toString(a));
            System.out.println(Arrays.stream(a).distinct().count() < 2);
            System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
        }
    }
}

Python: all(a == nexta for a, nexta in zip(strings, strings[1:])) 
all(a < nexta for a, nexta in zip(strings, strings[1:])) 

len(set(strings)) == 1  
sorted(strings, reverse=True) == strings
Task: Compare a list of strings
Java: import java.util.Arrays;

public class CompareListOfStrings {

    public static void main(String[] args) {
        String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
        for (String[] a : arr) {
            System.out.println(Arrays.toString(a));
            System.out.println(Arrays.stream(a).distinct().count() < 2);
            System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
        }
    }
}

VB: Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean

    On Error Resume Next
    If UBound(myList) > 0 Then
        If Err.Number > 0 Then
            IsEqualOrAscending = "Error " & Err.Number & " : Empty array"
            On Error GoTo 0
            Exit Function
        Else
            For i = 1 To UBound(myList)
                If myList(i) <> myList(i - 1) Then boolEqual = True
                If myList(i) <= myList(i - 1) Then boolAsc = True
            Next
        End If
    End If
    IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
Task: Compare a list of strings
Go: package cmp

func AllEqual(strings []string) bool {
	for _, s := range strings {
		if s != strings[0] {
			return false
		}
	}
	return true
}

func AllLessThan(strings []string) bool {
	for i := 1; i < len(strings); i++ {
		if !(strings[i - 1] < s) {
			return false
		}
	}
	return true
}

Python: all(a == nexta for a, nexta in zip(strings, strings[1:])) 
all(a < nexta for a, nexta in zip(strings, strings[1:])) 

len(set(strings)) == 1  
sorted(strings, reverse=True) == strings
Task: Compare a list of strings
Go: package cmp

func AllEqual(strings []string) bool {
	for _, s := range strings {
		if s != strings[0] {
			return false
		}
	}
	return true
}

func AllLessThan(strings []string) bool {
	for i := 1; i < len(strings); i++ {
		if !(strings[i - 1] < s) {
			return false
		}
	}
	return true
}

VB: Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean

    On Error Resume Next
    If UBound(myList) > 0 Then
        If Err.Number > 0 Then
            IsEqualOrAscending = "Error " & Err.Number & " : Empty array"
            On Error GoTo 0
            Exit Function
        Else
            For i = 1 To UBound(myList)
                If myList(i) <> myList(i - 1) Then boolEqual = True
                If myList(i) <= myList(i - 1) Then boolAsc = True
            Next
        End If
    End If
    IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
Task: Compare a list of strings
Python: all(a == nexta for a, nexta in zip(strings, strings[1:])) 
all(a < nexta for a, nexta in zip(strings, strings[1:])) 

len(set(strings)) == 1  
sorted(strings, reverse=True) == strings  

VB: Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean

    On Error Resume Next
    If UBound(myList) > 0 Then
        If Err.Number > 0 Then
            IsEqualOrAscending = "Error " & Err.Number & " : Empty array"
            On Error GoTo 0
            Exit Function
        Else
            For i = 1 To UBound(myList)
                If myList(i) <> myList(i - 1) Then boolEqual = True
                If myList(i) <= myList(i - 1) Then boolAsc = True
            Next
        End If
    End If
    IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
Task: Compare a list of strings
C: #include <stdbool.h>
#include <string.h>

static bool
strings_are_equal(const char **strings, size_t nstrings)
{
    for (size_t i = 1; i < nstrings; i++)
        if (strcmp(strings[0], strings[i]) != 0)
            return false;
    return true;
}

static bool
strings_are_in_ascending_order(const char **strings, size_t nstrings)
{
    for (size_t i = 1; i < nstrings; i++)
        if (strcmp(strings[i - 1], strings[i]) >= 0)
            return false;
    return true;
}

Java: import java.util.Arrays;

public class CompareListOfStrings {

    public static void main(String[] args) {
        String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
        for (String[] a : arr) {
            System.out.println(Arrays.toString(a));
            System.out.println(Arrays.stream(a).distinct().count() < 2);
            System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
        }
    }
}
Task: Compare a list of strings
C#: public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
    strings.Count < 2 ? (true, true) :
    (
        strings.Distinct().Count() < 2,
        Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
    );

Java: import java.util.Arrays;

public class CompareListOfStrings {

    public static void main(String[] args) {
        String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
        for (String[] a : arr) {
            System.out.println(Arrays.toString(a));
            System.out.println(Arrays.stream(a).distinct().count() < 2);
            System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
        }
    }
}
Task: Ordered words
C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>


#define MAXLEN 100
typedef char TWord[MAXLEN];


typedef struct Node {
    TWord word;
    struct Node *next;
} Node;


int is_ordered_word(const TWord word) {
    assert(word != NULL);
    int i;

    for (i = 0; word[i] != '\0'; i++)
        if (word[i] > word[i + 1] && word[i + 1] != '\0')
            return 0;

    return 1;
}


Node* list_prepend(Node* words_list, const TWord new_word) {
    assert(new_word != NULL);
    Node *new_node = malloc(sizeof(Node));
    if (new_node == NULL)
        exit(EXIT_FAILURE);

    strcpy(new_node->word, new_word);
    new_node->next = words_list;
    return new_node;
}


Node* list_destroy(Node *words_list) {
    while (words_list != NULL) {
        Node *temp = words_list;
        words_list = words_list->next;
        free(temp);
    }

    return words_list;
}


void list_print(Node *words_list) {
    while (words_list != NULL) {
        printf("\n%s", words_list->word);
        words_list = words_list->next;
    }
}


int main() {
    FILE *fp = fopen("unixdict.txt", "r");
    if (fp == NULL)
        return EXIT_FAILURE;

    Node *words = NULL;
    TWord line;
    unsigned int max_len = 0;

    while (fscanf(fp, "%99s\n", line) != EOF) {
        if (strlen(line) > max_len && is_ordered_word(line)) {
            max_len = strlen(line);
            words = list_destroy(words);
            words = list_prepend(words, line);
        } else if (strlen(line) == max_len && is_ordered_word(line)) {
            words = list_prepend(words, line);
        }
    }

    fclose(fp);
    list_print(words);

    return EXIT_SUCCESS;
}

C#: using System;
using System.Linq;
using System.Net;

static class Program
{
    static void Main(string[] args)
    {
        WebClient client = new WebClient();
        string text = client.DownloadString("http:
        string[] words = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

        var query = from w in words
                    where IsOrderedWord(w)
                    group w by w.Length into ows
                    orderby ows.Key descending
                    select ows;

        Console.WriteLine(string.Join(", ", query.First().ToArray()));
    }

    private static bool IsOrderedWord(string w)
    {
        for (int i = 1; i < w.Length; i++)
            if (w[i] < w[i - 1])
                return false;

        return true;
    }
}
Task: Ordered words
C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>


#define MAXLEN 100
typedef char TWord[MAXLEN];


typedef struct Node {
    TWord word;
    struct Node *next;
} Node;


int is_ordered_word(const TWord word) {
    assert(word != NULL);
    int i;

    for (i = 0; word[i] != '\0'; i++)
        if (word[i] > word[i + 1] && word[i + 1] != '\0')
            return 0;

    return 1;
}


Node* list_prepend(Node* words_list, const TWord new_word) {
    assert(new_word != NULL);
    Node *new_node = malloc(sizeof(Node));
    if (new_node == NULL)
        exit(EXIT_FAILURE);

    strcpy(new_node->word, new_word);
    new_node->next = words_list;
    return new_node;
}


Node* list_destroy(Node *words_list) {
    while (words_list != NULL) {
        Node *temp = words_list;
        words_list = words_list->next;
        free(temp);
    }

    return words_list;
}


void list_print(Node *words_list) {
    while (words_list != NULL) {
        printf("\n%s", words_list->word);
        words_list = words_list->next;
    }
}


int main() {
    FILE *fp = fopen("unixdict.txt", "r");
    if (fp == NULL)
        return EXIT_FAILURE;

    Node *words = NULL;
    TWord line;
    unsigned int max_len = 0;

    while (fscanf(fp, "%99s\n", line) != EOF) {
        if (strlen(line) > max_len && is_ordered_word(line)) {
            max_len = strlen(line);
            words = list_destroy(words);
            words = list_prepend(words, line);
        } else if (strlen(line) == max_len && is_ordered_word(line)) {
            words = list_prepend(words, line);
        }
    }

    fclose(fp);
    list_print(words);

    return EXIT_SUCCESS;
}

C++: #include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

bool ordered(const std::string &word)
{
    return std::is_sorted(word.begin(), word.end()); 
}

int main()
{
    std::ifstream infile("unixdict.txt");
    if (!infile) {
        std::cerr << "Can't open word file\n";
        return -1;
    }

    std::vector<std::string> words;
    std::string word;
    int longest = 0;

    while (std::getline(infile, word)) {
        int length = word.length();
        if (length < longest) continue; 
        
        if (ordered(word)) {
            if (longest < length) {
                longest = length; 
                words.clear(); 
            }
            words.push_back(word);
        }
    }
    std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}
Task: Ordered words
C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>


#define MAXLEN 100
typedef char TWord[MAXLEN];


typedef struct Node {
    TWord word;
    struct Node *next;
} Node;


int is_ordered_word(const TWord word) {
    assert(word != NULL);
    int i;

    for (i = 0; word[i] != '\0'; i++)
        if (word[i] > word[i + 1] && word[i + 1] != '\0')
            return 0;

    return 1;
}


Node* list_prepend(Node* words_list, const TWord new_word) {
    assert(new_word != NULL);
    Node *new_node = malloc(sizeof(Node));
    if (new_node == NULL)
        exit(EXIT_FAILURE);

    strcpy(new_node->word, new_word);
    new_node->next = words_list;
    return new_node;
}


Node* list_destroy(Node *words_list) {
    while (words_list != NULL) {
        Node *temp = words_list;
        words_list = words_list->next;
        free(temp);
    }

    return words_list;
}


void list_print(Node *words_list) {
    while (words_list != NULL) {
        printf("\n%s", words_list->word);
        words_list = words_list->next;
    }
}


int main() {
    FILE *fp = fopen("unixdict.txt", "r");
    if (fp == NULL)
        return EXIT_FAILURE;

    Node *words = NULL;
    TWord line;
    unsigned int max_len = 0;

    while (fscanf(fp, "%99s\n", line) != EOF) {
        if (strlen(line) > max_len && is_ordered_word(line)) {
            max_len = strlen(line);
            words = list_destroy(words);
            words = list_prepend(words, line);
        } else if (strlen(line) == max_len && is_ordered_word(line)) {
            words = list_prepend(words, line);
        }
    }

    fclose(fp);
    list_print(words);

    return EXIT_SUCCESS;
}

Go: package main

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

func main() {
    
    b, err := ioutil.ReadFile("unixdict.txt")
    if err != nil {
        fmt.Println(err)
        return
    }
    
    bss := bytes.Split(b, []byte{'\n'})

    
    var longest int
    var list [][]byte
    for _, bs := range bss {
        
        
        if len(bs) < longest {
            continue
        }
        
        var lastLetter byte
        for i := 0; ; i++ {
            if i == len(bs) {
                
                
                if len(bs) > longest {
                    longest = len(bs)
                    list = list[:0]
                }
                list = append(list, bs)
                break
            }
            
            b := bs[i]
            if b < 'a' || b > 'z' {
                continue 
            }
            if b < lastLetter {
                break 
            }
            
            lastLetter = b
        }
    }
    
    for _, bs := range list {
        fmt.Println(string(bs))
    }
}
Task: Ordered words
C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>


#define MAXLEN 100
typedef char TWord[MAXLEN];


typedef struct Node {
    TWord word;
    struct Node *next;
} Node;


int is_ordered_word(const TWord word) {
    assert(word != NULL);
    int i;

    for (i = 0; word[i] != '\0'; i++)
        if (word[i] > word[i + 1] && word[i + 1] != '\0')
            return 0;

    return 1;
}


Node* list_prepend(Node* words_list, const TWord new_word) {
    assert(new_word != NULL);
    Node *new_node = malloc(sizeof(Node));
    if (new_node == NULL)
        exit(EXIT_FAILURE);

    strcpy(new_node->word, new_word);
    new_node->next = words_list;
    return new_node;
}


Node* list_destroy(Node *words_list) {
    while (words_list != NULL) {
        Node *temp = words_list;
        words_list = words_list->next;
        free(temp);
    }

    return words_list;
}


void list_print(Node *words_list) {
    while (words_list != NULL) {
        printf("\n%s", words_list->word);
        words_list = words_list->next;
    }
}


int main() {
    FILE *fp = fopen("unixdict.txt", "r");
    if (fp == NULL)
        return EXIT_FAILURE;

    Node *words = NULL;
    TWord line;
    unsigned int max_len = 0;

    while (fscanf(fp, "%99s\n", line) != EOF) {
        if (strlen(line) > max_len && is_ordered_word(line)) {
            max_len = strlen(line);
            words = list_destroy(words);
            words = list_prepend(words, line);
        } else if (strlen(line) == max_len && is_ordered_word(line)) {
            words = list_prepend(words, line);
        }
    }

    fclose(fp);
    list_print(words);

    return EXIT_SUCCESS;
}

Java: import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class Ordered {

	private static boolean isOrderedWord(String word){
		char[] sortedWord = word.toCharArray();
		Arrays.sort(sortedWord);
		return word.equals(new String(sortedWord));
	}
	
	public static void main(String[] args) throws IOException{
		List<String> orderedWords = new LinkedList<String>();
		BufferedReader in = new BufferedReader(new FileReader(args[0]));
		while(in.ready()){
			String word = in.readLine();
			if(isOrderedWord(word)) orderedWords.add(word);
		}
		in.close();
		
		Collections.<String>sort(orderedWords, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return new Integer(o2.length()).compareTo(o1.length());
			}
		});
		
		int maxLen = orderedWords.get(0).length();
		for(String word: orderedWords){
			if(word.length() == maxLen){
				System.out.println(word);
			}else{
				break;
			}
		}
	}
}
Task: Ordered words
C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>


#define MAXLEN 100
typedef char TWord[MAXLEN];


typedef struct Node {
    TWord word;
    struct Node *next;
} Node;


int is_ordered_word(const TWord word) {
    assert(word != NULL);
    int i;

    for (i = 0; word[i] != '\0'; i++)
        if (word[i] > word[i + 1] && word[i + 1] != '\0')
            return 0;

    return 1;
}


Node* list_prepend(Node* words_list, const TWord new_word) {
    assert(new_word != NULL);
    Node *new_node = malloc(sizeof(Node));
    if (new_node == NULL)
        exit(EXIT_FAILURE);

    strcpy(new_node->word, new_word);
    new_node->next = words_list;
    return new_node;
}


Node* list_destroy(Node *words_list) {
    while (words_list != NULL) {
        Node *temp = words_list;
        words_list = words_list->next;
        free(temp);
    }

    return words_list;
}


void list_print(Node *words_list) {
    while (words_list != NULL) {
        printf("\n%s", words_list->word);
        words_list = words_list->next;
    }
}


int main() {
    FILE *fp = fopen("unixdict.txt", "r");
    if (fp == NULL)
        return EXIT_FAILURE;

    Node *words = NULL;
    TWord line;
    unsigned int max_len = 0;

    while (fscanf(fp, "%99s\n", line) != EOF) {
        if (strlen(line) > max_len && is_ordered_word(line)) {
            max_len = strlen(line);
            words = list_destroy(words);
            words = list_prepend(words, line);
        } else if (strlen(line) == max_len && is_ordered_word(line)) {
            words = list_prepend(words, line);
        }
    }

    fclose(fp);
    list_print(words);

    return EXIT_SUCCESS;
}

Python: import urllib.request

url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
words = urllib.request.urlopen(url).read().decode("utf-8").split()
ordered = [word for word in words if word==''.join(sorted(word))]
maxlen = len(max(ordered, key=len))
maxorderedwords = [word for word in ordered if len(word) == maxlen]
print(' '.join(maxorderedwords))
Task: Ordered words
C#: using System;
using System.Linq;
using System.Net;

static class Program
{
    static void Main(string[] args)
    {
        WebClient client = new WebClient();
        string text = client.DownloadString("http:
        string[] words = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

        var query = from w in words
                    where IsOrderedWord(w)
                    group w by w.Length into ows
                    orderby ows.Key descending
                    select ows;

        Console.WriteLine(string.Join(", ", query.First().ToArray()));
    }

    private static bool IsOrderedWord(string w)
    {
        for (int i = 1; i < w.Length; i++)
            if (w[i] < w[i - 1])
                return false;

        return true;
    }
}

C++: #include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

bool ordered(const std::string &word)
{
    return std::is_sorted(word.begin(), word.end()); 
}

int main()
{
    std::ifstream infile("unixdict.txt");
    if (!infile) {
        std::cerr << "Can't open word file\n";
        return -1;
    }

    std::vector<std::string> words;
    std::string word;
    int longest = 0;

    while (std::getline(infile, word)) {
        int length = word.length();
        if (length < longest) continue; 
        
        if (ordered(word)) {
            if (longest < length) {
                longest = length; 
                words.clear(); 
            }
            words.push_back(word);
        }
    }
    std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}