Anagrams: Difference between revisions

Content added Content deleted
Line 199: Line 199:
void main() {
void main() {
string[][string] anags;
string[][string] anags;
foreach (string w; new BufferedFile("unixdict.txt"))
anags[w.dup.sort] ~= w.dup;
int lmax;
int lmax;
foreach (a; anags)
foreach (string w; new BufferedFile("unixdict.txt")) {
lmax = lmax < a.length ? a.length : lmax;
string wrd = w.dup;
string key = wrd.sort;
foreach (a; anags)
if (a.length == lmax)
anags[key] ~= wrd;
int len = anags[key].length;
lmax = lmax < len ? len : lmax;
}
foreach (a; anags) {
if (a.length == lmax) {
writefln(a);
writefln(a);
}
}
}
}
</lang>
</lang>