Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Anagrams/D/anagrams-1.d
Normal file
9
Task/Anagrams/D/anagrams-1.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import std.stdio, std.algorithm, std.string, std.exception, std.file;
|
||||
|
||||
void main() {
|
||||
string[][ubyte[]] an;
|
||||
foreach (w; "unixdict.txt".readText.splitLines)
|
||||
an[w.dup.representation.sort().release.assumeUnique] ~= w;
|
||||
immutable m = an.byValue.map!q{ a.length }.reduce!max;
|
||||
writefln("%(%s\n%)", an.byValue.filter!(ws => ws.length == m));
|
||||
}
|
||||
14
Task/Anagrams/D/anagrams-2.d
Normal file
14
Task/Anagrams/D/anagrams-2.d
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
void main() {
|
||||
import std.stdio, std.algorithm, std.file, std.string;
|
||||
|
||||
auto keys = "unixdict.txt".readText!(char[]);
|
||||
immutable vals = keys.idup;
|
||||
string[][string] anags;
|
||||
foreach (w; keys.splitter) {
|
||||
immutable k = w.representation.sort().release.assumeUTF;
|
||||
anags[k] ~= vals[k.ptr - keys.ptr .. k.ptr - keys.ptr + k.length];
|
||||
}
|
||||
//immutable m = anags.byValue.maxs!q{ a.length };
|
||||
immutable m = anags.byValue.map!q{ a.length }.reduce!max;
|
||||
writefln("%(%-(%s %)\n%)", anags.byValue.filter!(ws => ws.length == m));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue