mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-06 22:28:49 -04:00
abstracted structures fixed
This commit is contained in:
parent
3fdbc2a605
commit
01703751f1
98 changed files with 305 additions and 856 deletions
16
src/builtin_structures/fibonacci.py
Normal file → Executable file
16
src/builtin_structures/fibonacci.py
Normal file → Executable file
|
@ -33,6 +33,22 @@ def fib(n):
|
|||
return b
|
||||
|
||||
|
||||
def fib_rec(n):
|
||||
'''
|
||||
>>> fib_rec(2)
|
||||
1
|
||||
>>> fib_rec(5)
|
||||
5
|
||||
>>> fib_rec(7)
|
||||
13
|
||||
'''
|
||||
if n < 3:
|
||||
return 1
|
||||
return fib_rec(n - 1) + fib_rec(n - 2)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue