Skip to content

Instantly share code, notes, and snippets.

@emadshaaban92
Created January 31, 2014 22:02
Show Gist options
  • Save emadshaaban92/8744165 to your computer and use it in GitHub Desktop.
Save emadshaaban92/8744165 to your computer and use it in GitHub Desktop.
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