Skip to content

Instantly share code, notes, and snippets.

@sammylupt
Created February 10, 2016 17:24
Show Gist options
  • Save sammylupt/5ea2ce46fc58b6e88ae8 to your computer and use it in GitHub Desktop.
Save sammylupt/5ea2ce46fc58b6e88ae8 to your computer and use it in GitHub Desktop.
defmodule HappyNumberFinder do
def get_sum(number) do
number
|> Integer.digits #=> [4, 9]
|> Enum.map(&(&1 * &1)) #=> [16, 81]
|> Enum.reduce(&(&1 + &2)) #=> 97
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment