Created
July 27, 2013 01:14
-
-
Save ToJans/6093258 to your computer and use it in GitHub Desktop.
Anagram koan
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 Anagram do | |
@doc """ | |
# Anagram | |
Given a word and a list of possible anagrams, selects the correct one(s). | |
## Example | |
iex> Anagram.match "listen",%w(enlists google inlets banana) | |
["inlets"] | |
""" | |
def match(word,words) do | |
normalized_word = normalize_word(word) | |
Enum.filter words, fn x -> normalized_word==normalize_word(x) end | |
end | |
defp normalize_word(word) do | |
word |> String.codepoints |> Enum.sort | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment