Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,43 @@
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;
}
}
}
}

View file

@ -0,0 +1,25 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public final class OrderedWords {
public static void main(String[] aArgs) throws IOException {
List<String> ordered = Files.lines(Path.of("unixdict.txt"))
.filter( word -> isOrdered(word) ).toList();
final int maxLength = ordered.stream().map( word -> word.length() ).max(Integer::compare).get();
ordered.stream().filter( word -> word.length() == maxLength ).forEach(System.out::println);
}
private static boolean isOrdered(String aWord) {
return aWord.chars()
.mapToObj( i -> (char) i )
.sorted()
.map(String::valueOf)
.reduce("", String::concat)
.equals(aWord);
}
}