We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d4d94d4 commit 1fca966Copy full SHA for 1fca966
1 file changed
maths/leonardo_numbers.py
@@ -1,13 +1,13 @@
1
def leonardo_numbers(n: int) -> int:
2
"""
3
Return the n-th Leonardo number.
4
-
+
5
The Leonardo numbers are a sequence of numbers given by the recurrence:
6
L(n) = L(n-1) + L(n-2) + 1
7
with initial values L(0) = 1 and L(1) = 1.
8
9
Reference: https://en.wikipedia.org/wiki/Leonardo_number
10
11
>>> leonardo_numbers(0)
12
13
>>> leonardo_numbers(1)
@@ -31,16 +31,18 @@ def leonardo_numbers(n: int) -> int:
31
32
if not isinstance(n, int) or n < 0:
33
raise ValueError("n must be a non-negative integer")
34
35
if n == 0 or n == 1:
36
return 1
37
38
a, b = 1, 1
39
for _ in range(n - 1):
40
a, b = b, a + b + 1
41
42
return b
43
44
45
if __name__ == "__main__":
46
import doctest
- doctest.testmod()
47
48
+ doctest.testmod()
0 commit comments