Skip to content

Instantly share code, notes, and snippets.

@sammylupt
Created February 10, 2016 17:21
Show Gist options
  • Save sammylupt/3077b45254601cd744fe to your computer and use it in GitHub Desktop.
Save sammylupt/3077b45254601cd744fe to your computer and use it in GitHub Desktop.
defmodule HappyNumberFinder do
def get_sum(number) do
numbers = Integer.digits(number) #=> [4, 9]
squared_numbers = Enum.map(numbers, fn(x) -> x * x end) #=> [16, 81]
sum = Enum.reduce(squared_numbers, 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