Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

pirj commented Sep 5, 2012

cool!

@pirj

This comment has been minimized.

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
You can’t perform that action at this time.