Skip to content

Instantly share code, notes, and snippets.

@trescenzi
Last active August 29, 2015 14:27
Show Gist options
  • Save trescenzi/7a33373a52c9744aefdb to your computer and use it in GitHub Desktop.
Save trescenzi/7a33373a52c9744aefdb to your computer and use it in GitHub Desktop.
def fibonacci_stream do
Stream.unfold( [1], fn
[prev, curr] ->
next = prev + curr
{next, [curr, next]}
([1]) ->
{1, [1,1]}
end)
end
def euler do
fibonacci_stream
|> Enum.take_while(fn x -> x < 4000000 end)
|> Enum.filter(fn x -> Integer.is_even(x) end)
|> Enum.sum()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment