Created
April 17, 2017 13:30
-
-
Save slofurno/c037cabc3aaaf57d93a7ba0697eab21c to your computer and use it in GitHub Desktop.
This file contains 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 S do | |
def anagram(xs, ys) do | |
count(xs) == count(ys) | |
end | |
defp count(xs), do: count(xs, %{}) | |
defp count(<<>>, seen), do: seen | |
defp count(<<x::utf8, rest::binary>>, seen) do | |
count(rest, Map.put(seen, x, (seen[x] || 0) + 1)) | |
end | |
def test do | |
true = anagram("asdf", "fdsa") | |
false = anagram("aaaa", "aaa") | |
:ok | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment