Before the Fibonacci sequence was counted as the sum of the first two numbers.
such as 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
2=1+1
3=1+2
5=2+3
8=3+5
......
In fact, there is another rule:
2 = 1*2-0
3 = 2*2-1
5 = 3*2-1
8 = 5*2-2
13= 8*2-3
21=13*2-5
......
The following is the JS implementation of the Code:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metahttp-equiv= "X-ua-compatible"content= "Ie=edge,chrome=1"><title>JS Fibonacci sequence</title><Metaname= "description"content= "js Fibonacci sequence"><Metaname= "keywords"content= "js Fibonacci sequence"><Linkhref=""rel= "stylesheet"><Scripttype= "Text/javascript"> /*found a magic algorithm to simplify the Fibonacci sequence, handy with JS implementation. The following key sentences are the rules 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 You can find 2 = 1*2-0 3 = 2*2-1 5 = 3*2-1 8 = 5*2-2 13 = 8*2-3 21=13*2-5 ... You know the following.*/ vara= []; a[0]=0; a[1]=1; a[2]=1; vari; for(i=3; I< About; I++) {A[i]= 2*A[i-1]-A[i-3];/*Key Sentence*/Console.log (A[i]); }</Script></Head><Body> </Body></HTML>
-JS realization of the Fibonacci sequence formula algorithm