Last active
August 29, 2015 14:27
-
-
Save trescenzi/7a33373a52c9744aefdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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