Skip to content

Instantly share code, notes, and snippets.

@israelst
Last active September 27, 2015 08:27
Show Gist options
  • Save israelst/1240259 to your computer and use it in GitHub Desktop.
Save israelst/1240259 to your computer and use it in GitHub Desktop.
A lazy fibonacci example written in javascript
function create_fibonacci(){
var n1 = -1,
n2 = 1,
n = 0;
return function(){
n = n1 + n2;
n1 = n2;
n2 = n;
return n;
}
}
var fib = create_fibonacci();
for(var i = 0; i<=15; i++){
console.log(fib());
}
@juanplopes
Copy link

def fibs():
    a,b=(0,1)
    while(true):
        a,b=(a+b,a) 
        yield a

for i in fibs().Take(15):
   print i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment