Skip to content

Instantly share code, notes, and snippets.

@damrkul
Created December 2, 2014 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damrkul/c6c570f1ed09f6fcb833 to your computer and use it in GitHub Desktop.
Save damrkul/c6c570f1ed09f6fcb833 to your computer and use it in GitHub Desktop.
defmodule Dupe do
def main(:done, list) do
list
|> HashDict.to_list
|> Enum.sort
|> Enum.map(fn(x) -> if elem(x,1) > 1 do IO.puts "#{elem(x,0)} (#{elem(x,1)})" end end)
end
def main(_,list) do
line = readline()
list = insert(list, line)
main(line,list)
end
def insert(dict, key ) do
if HashDict.has_key?(dict, key) do
HashDict.put(dict, key, HashDict.get(dict, key)+ 1 )
else
HashDict.put(dict, key, 1)
end
end
defp readline, do: IO.read(:line) |> process
defp process(:eof), do: :done
defp process(line), do: line |> remove_new_line
defp remove_new_line(str), do: String.replace(str, ~r/\n/, "")
end
Dupe.main("" ,HashDict.new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment