Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
25
Task/Anagrams/Elixir/anagrams-1.elixir
Normal file
25
Task/Anagrams/Elixir/anagrams-1.elixir
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
defmodule Anagrams do
|
||||
def find(file) do
|
||||
File.read!(file)
|
||||
|> String.split
|
||||
|> Enum.map(&String.codepoints &1)
|
||||
|> sort(%{})
|
||||
|> Enum.group_by(fn {_,v} -> length(v) end)
|
||||
|> Enum.max
|
||||
|> print
|
||||
end
|
||||
|
||||
defp sort([],m), do: m
|
||||
defp sort([word|words],m) do
|
||||
s = Enum.sort(word)
|
||||
m = Dict.update(m, s, [word], fn val -> [word|val] end)
|
||||
sort(words,m)
|
||||
end
|
||||
|
||||
defp print({_,y}) do
|
||||
Enum.each(y, fn {_,e} ->
|
||||
Enum.map(e, &Enum.join(&1)) |> Enum.sort |> Enum.join(" ") |> IO.puts
|
||||
end)
|
||||
end
|
||||
end
|
||||
Anagrams.find("unixdict.txt")
|
||||
13
Task/Anagrams/Elixir/anagrams-2.elixir
Normal file
13
Task/Anagrams/Elixir/anagrams-2.elixir
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
File.stream!("unixdict.txt")
|
||||
|> Stream.map(&String.strip &1)
|
||||
|> Stream.map(&{&1, &1 |> String.codepoints |> Enum.sort |> Enum.join})
|
||||
|> Enum.group_by(fn {_,y} -> y end)
|
||||
|> Dict.values
|
||||
|> Enum.group_by(&length(&1))
|
||||
|> Enum.max
|
||||
|> elem(1)
|
||||
|> Enum.each(fn n -> Enum.map(n, fn {y,_} -> y end)
|
||||
|> Enum.sort
|
||||
|> Enum.join(" ")
|
||||
|> IO.puts
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue