Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created July 27, 2013 01:14
Show Gist options
  • Save ToJans/6093258 to your computer and use it in GitHub Desktop.
Save ToJans/6093258 to your computer and use it in GitHub Desktop.
Anagram koan
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