Created
January 31, 2014 22:02
-
-
Save emadshaaban92/8744165 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type fib = iter(int) | |
MAX = 4000000 | |
function fib fibs_init(a,b) { | |
{ next : function () { some((a, fibs_init(b, a+b))) } } | |
} | |
fib fibs = fibs_init(1,2) | |
fib even_fibs = Iter.filter(function (elm){ mod(elm, 2) == 0 }, fibs) | |
fib even_fibs_under_max = Iter.take_while(function (elm){ elm < MAX } , even_fibs) | |
jlog( Int.to_string(Iter.fold(function (elm, acc){ elm + acc }, even_fibs_under_max, 0)) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment