RosettaCodeData/Task/Anagrams/Elixir/anagrams-1.elixir

17 lines
381 B
Text
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
defmodule Anagrams do
def find(file) do
File.read!(file)
|> String.split
2016-12-05 22:15:40 +01:00
|> Enum.group_by(fn word -> String.codepoints(word) |> Enum.sort end)
2015-11-18 06:14:39 +00:00
|> Enum.group_by(fn {_,v} -> length(v) end)
|> Enum.max
|> print
end
defp print({_,y}) do
2016-12-05 22:15:40 +01:00
Enum.each(y, fn {_,e} -> Enum.sort(e) |> Enum.join(" ") |> IO.puts end)
2015-11-18 06:14:39 +00:00
end
end
2016-12-05 22:15:40 +01:00
2015-11-18 06:14:39 +00:00
Anagrams.find("unixdict.txt")