File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 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+
110def 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
4548if __name__ == "__main__" :
4649 import doctest
4750
48- doctest .testmod ()
51+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments