0,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,.....
def fibonacciVal(n): if n == 0: return 0 elif n == 1: return 1 else: return fibonacciVal(n-1) + fibonacciVal(n-2)
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
5702887
9227465
14930352
24157817
39088169
63245986
function Fibonacci(num){
var before = 0;
var actual = 1;
var next = 1;
for(let i = 0; i < num; i++){
console.log(next)
before = actual + next;
actual = next
next = before
}
}
Fibonacci(100);
python fibo.py <arguments>
f(n) = f(n-1) + f(n-2)
f(6)
^
/
f(5) + f(4)
^
/ /
f(4) + f(3) f(3) + f(2)
^ ^ ^ ^
/ / / /
f(3) + f(2) f(2) +f(1) f(2) + f(1) f(1) + f(0)
^ ^ ^ ^
/ / / /
f(2) + f(1) f(1) + f(0) f(1)+ f(0) f(1) + f(0)
^
/
f(1) + f(0)
//f(6) = 8 ==> f(1)*8 f(1) appears 8 times
double feb = (1/Math.pow(5,0.5)) * (Math.pow((1+Math.pow(5,0.5))/2,n)) - (1/Math.pow(5,0.5))* (Math.pow((1-Math.pow(5,0.5))/2,n));
f(1) == 1;