Fibonacci sequence
In mathematics, the Fibonacci sequence is a sequence in which each number is the sum of the two numbers that precede it. Numbers that are part of the sequence are known as Fibonacci numbers. The Fibonacci number is represented by .
Head Recursive Fibonacci
// rust
# python
return 0
== 1:
return 1
return +
Tail Recursive Fibonacci
(* ocaml *)
if n = 0 then a
else fib b
in
fib n 0 1
-- haskell
fib n 0 1
where
fib 0 a _ = a
fib n a b = fib (n - 1) b (a + b)