← Back to challenges

Amount of Fibonacci Numbers

PythonHardalgebraalgorithmsmathnumbers

Instructions

Create a function that returns the amount of Fibonacci numbers strictly smaller than the given integer. In mathematics, the Fibonacci numbers commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. Thus:

F0=0 and F1=1

and

Fn=F(n-1)+F(n-2)

for n > 1

The beginning of the sequence is thus:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

The function should thus return 13 when called with the variable n = 145 since there exist 13 Fibonacci numbers strictly smaller than 145.

Examples

amount_fib(0) ➞ 0

amount_fib(1) ➞ 1

amount_fib(3) ➞ 4

amount_fib(22) ➞ 9

amount_fib(145) ➞ 13

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.