Skip to content

Instantly share code, notes, and snippets.

@ikataitsev
Created September 28, 2012 05:50
Show Gist options
  • Save ikataitsev/3798133 to your computer and use it in GitHub Desktop.
Save ikataitsev/3798133 to your computer and use it in GitHub Desktop.
Calculating Fibonacci series with dictionary
def fib n, dict = []
if n < 2
dict[0] = 1
else
dict[n-1] = ( dict[n-2] || fib(n-1, dict).last ) + ( dict[n-3] || fib(n-2, dict).last )
end
dict
end
@arunkumardancer
Copy link

Here is the recursive equation to generate fibonacci series using recursion.
fibonacci(N) = Nth term in fibonacci series
fibonacci(N) = fibonacci(N - 1) + fibonacci(N - 2);
whereas, fibonacci(0) = 0 and fibonacci(1) = 1

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