RosettaCodeData/Task/Ordered-words/D/ordered-words-1.d

21 lines
475 B
D
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
void main() {
import std.stdio, std.algorithm, std.range, std.string;
string[] result;
size_t maxLen;
foreach (string word; "unixdict.txt".File.lines) {
word = word.chomp;
immutable len = word.walkLength;
if (len < maxLen || !word.isSorted)
continue;
if (len > maxLen) {
result = [word];
maxLen = len;
} else
result ~= word;
}
writefln("%-(%s\n%)", result);
}