RosettaCodeData/Task/Anagrams/Component-Pascal/anagrams-3.component

15 lines
558 B
Text
Raw Permalink Normal View History

2013-10-27 22:24:23 +00:00
void main() {
2015-02-20 00:35:01 -05:00
import std.stdio, std.algorithm, std.file, std.string;
auto keys = "unixdict.txt".readText!(char[]);
2013-10-27 22:24:23 +00:00
immutable vals = keys.idup;
string[][string] anags;
foreach (w; keys.splitter) {
2015-02-20 00:35:01 -05:00
immutable k = w.representation.sort().release.assumeUTF;
anags[k] ~= vals[k.ptr - keys.ptr .. k.ptr - keys.ptr + k.length];
2013-10-27 22:24:23 +00:00
}
2015-02-20 00:35:01 -05:00
//immutable m = anags.byValue.maxs!q{ a.length };
2013-10-27 22:24:23 +00:00
immutable m = anags.byValue.map!q{ a.length }.reduce!max;
2015-02-20 00:35:01 -05:00
writefln("%(%-(%s %)\n%)", anags.byValue.filter!(ws => ws.length == m));
2013-10-27 22:24:23 +00:00
}