Next, I would like to introduce the Tribonacci series, the big brother of the Fibonacci series. Next, I would like to introduce the Tribonacci series, the big brother of the Fibonacci series.
As its name implies, it is similar to the Fibonacci series, but there are differences.
If we start this series with [, 1], we will get the following results:
[,...]
As you can see, item 4 3 is the sum of Items 1, 2, and 3, item 5 is the sum of items 2, 3, and 4, and so on ......
What will happen if we start this series with [, 1?
[, 24,...]
After reading this example, you probably have guessed the rule: Except for the first three digits used as the initial sequence, each digit in the future is equal to the sum of the three digits closest to it.
Then compare the Fibonacci series. The rule is: Except for the first two digits used as the initial sequence, each digit in the future is equal to the sum of the two digits closest to it.
Now, do you understand why I say they are brothers?
Even according to this rule, it can be extended to the Xbonacci series, but I will only talk about the Tribonacci series.
Okay. Think about how to construct a Tribonacci series!
It receives two parameters. The first parameter is an array as the initialization sequence. The second parameter is a number, indicating the number of columns to be generated.
The returned value is an array of Columns after a new item is generated.
There are two different situations for this problem:
First, what if the size of the initialization sequence is 3 but I only need to generate two items? The answer is simple. Just extract the first two items from the initialization array and you will be OK.
In the second case, it is very easy to generate items other than the initialization sequence. Just like generating a Fibonacci series, a cycle and new items are composed of the last three items, and so on.
Function tribonacci (signature, n) {var startPoint = 0; if (n <signature. length) {return signature. slice (0, n);} for (var I = startPoint + signature. length; I
The above is the content of the Tribonacci series. For more information, see the PHP Chinese website (www.php1.cn )!