Fibonacci sequence
In mathematics, the Fibonacci sequence is a sequence in which each number is the sum of the two preceding ones. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many writers begin the sequence with 0 and 1, although some authors start it from 1 and 1 and some (as did Fibonacci) from 1 and 2. Starting from 0 and 1, the sequence begins
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ....
.
— Wikipedia
Fiboancci Spiral
A Fibonacci spiral approximates the golden spiral using quarter-circle arcs inscribed in squares derived from the Fibonacci sequence.
Applications of Fibonacci numbers include computer algorithm:
Fibonacci sequence generation in Python
Main idea: each number is the sum of the two preceding ones, input is length of
Fibonacci sequence, output Fibonacci sequence. We need to store result of latest
calculation (sum of A
and B
), so we need to use temporary variable.
Results:
0
1
1
2
3
5
8
Simplified version