JonC 101 / Brainteaser Collection / Measuring 4 Liters with 3 and 5 Liter Jugs

The Fibonacci sequence is a somewhat fundamental mathematical/natural sequence whose core property is that every Fibonacci number is equal to the sum of the previous two numbers.

More formally,

Fib(n) = Fib(n-1) + Fib(n-2) and

Fib(0) = Fib(1) = 1.

This results in a sequence like 1, 1, 2, 3, 5, 8, 13, 21...

Write a function which takes one parameter, an integer "n" that returns the n-th number in the Fibonacci sequence.

Demo Application

Recursive Time (ms)
Iterative Time (ms)