Created
December 2, 2014 05:56
-
-
Save damrkul/c6c570f1ed09f6fcb833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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