Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #301 Recursive Fibonacci sequence

Compute the Fibonacci sequence of n numbers using recursion.

Note that naive recursion is extremely inefficient for this task.

def fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
int fibonacci(int n) => n <= 2 ? 1 : fibonacci(n - 2) + fibonacci(n - 1);

New implementation...
< >
Sikon