Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2012 19:22
Show Gist options
  • Save anonymous/4150061 to your computer and use it in GitHub Desktop.
Save anonymous/4150061 to your computer and use it in GitHub Desktop.
def fib2(n)
return n if n == 0 || n == 1
f = (0..n).to_a
f[0] = 0, f[1] = 1
i = 2
while i < n
f[i] = f[i-1] + f[i-2]
return f[i]
i += 1
end
end
puts fib2(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment