Skip to content

Instantly share code, notes, and snippets.

@NILID
Created September 5, 2012 14:34
Show Gist options
  • Save NILID/3637545 to your computer and use it in GitHub Desktop.
Save NILID/3637545 to your computer and use it in GitHub Desktop.
fibonacci
def fib(n)a,b,s=0,1,[];n.times{s<<a;a,b=b,a+b};s end
p fib(33)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, ...]
@pirj
Copy link

pirj commented Sep 5, 2012

cool!

@pirj
Copy link

pirj commented Sep 5, 2012

def fib3(n)a,b,s=0,1,[];n.times{s<<a;c=b;b=a+b;a=c};s end

4 bytes more, 3% faster

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