RosettaCodeData/Task/Word-wheel/Mathematica/word-wheel.math

16 lines
607 B
Plaintext

ClearAll[possible]
possible[letters_List][word_String] := Module[{c1, c2, m},
c1 = Counts[Characters@word];
c2 = Counts[letters];
m = Merge[{c1, c2}, Identity];
Length[Select[Select[m, Length /* GreaterThan[1]], Apply[Greater]]] == 0
]
chars = Characters@"ndeokgelw";
words = Import["http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "String"];
words = StringSplit[ToLowerCase[words], "\n"];
words //= Select[StringLength /* GreaterEqualThan[3]];
words //= Select[StringContainsQ["k"]];
words //= Select[StringMatchQ[Repeated[Alternatives @@ chars]]];
words //= Select[possible[chars]];
words