Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Created January 20, 2013 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanseys/4580753 to your computer and use it in GitHub Desktop.
Save ryanseys/4580753 to your computer and use it in GitHub Desktop.
Iterative Fibonacci Solution
def fib_i(n)
result = p1 = p2 = 1;
if(n > 1)
for i in 1..n
result = p1 + p2
p2 = p1
p1 = result
end
end
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment