Skip to content

Commit 273b09a

Browse files
committed
Rename variables to be more descriptive
1 parent b33434c commit 273b09a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

maths/leonardo_numbers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
"""
2+
Leonardo numbers are a sequence of numbers given by the recurrence:
3+
L(n) = L(n-1) + L(n-2) + 1
4+
with initial values L(0) = 1 and L(1) = 1.
5+
6+
Reference: https://en.wikipedia.org/wiki/Leonardo_number
7+
"""
8+
9+
110
def leonardo_numbers(n: int) -> int:
211
"""
312
Return the n-th Leonardo number.
413
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-
1114
>>> leonardo_numbers(0)
1215
1
1316
>>> leonardo_numbers(1)
@@ -35,14 +38,14 @@ def leonardo_numbers(n: int) -> int:
3538
if n == 0 or n == 1:
3639
return 1
3740

38-
a, b = 1, 1
41+
previous, current = 1, 1
3942
for _ in range(n - 1):
40-
a, b = b, a + b + 1
43+
previous, current = current, previous + current + 1
4144

42-
return b
45+
return current
4346

4447

4548
if __name__ == "__main__":
4649
import doctest
4750

48-
doctest.testmod()
51+
doctest.testmod()

0 commit comments

Comments
 (0)