Skip to content

Instantly share code, notes, and snippets.

@xikaos
Created July 29, 2016 17:57
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 xikaos/c3af6d1a7dc319583ca1d516f729f0a0 to your computer and use it in GitHub Desktop.
Save xikaos/c3af6d1a7dc319583ca1d516f729f0a0 to your computer and use it in GitHub Desktop.
defmodule Palindromes do
def run do
["amor", "roma", "phoenix", "mora", "elixir"]
|> Enum.group_by(&canonicalize/1)
|> IO.inspect
end
defp canonicalize(word) do
word
|> String.graphemes
|> Enum.sort
|> Enum.join
end
end
Palindromes.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment