Skip to content

Instantly share code, notes, and snippets.

@sammylupt
Created February 10, 2016 17:22
Show Gist options
  • Select an option

  • Save sammylupt/8da41674451e84e1ed03 to your computer and use it in GitHub Desktop.

Select an option

Save sammylupt/8da41674451e84e1ed03 to your computer and use it in GitHub Desktop.
defmodule HappyNumberFinder do
def get_sum(number) do
number
|> Integer.digits #=> [4, 9]
|> Enum.map(fn(x) -> x * x end) #=> [16, 81]
|> Enum.reduce(fn(x, total) -> x + total end) #=> 97
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment