pypkg_template package¶
Submodules¶
pypkg_template.fibonacci module¶
Various ways to calculate the Fibonacci sequence.
- class pypkg_template.fibonacci.ClassDP[source]¶
Bases:
object
A callable class internally memoizing the Fibonacci sequence.
Examples
>>> fib = ClassDP() >>> fib(0) 0 >>> fib(1) 1 >>> fib(2) 1 >>> fib(3) 2 >>> fib(4) 3
- pypkg_template.fibonacci.closuredp() collections.abc.Callable[[int], int] [source]¶
Return a closure that calculates the nth Fibonacci number.
- Returns:
A closure that calculates the nth Fibonacci number.
- Return type:
Examples
>>> fib = closuredp() >>> fib(0) 0 >>> fib(1) 1 >>> fib(2) 1 >>> fib(3) 2 >>> fib(4) 3
- pypkg_template.fibonacci.naive(n: int) int [source]¶
Calculate the nth Fibonacci number using a naive recursive algorithm.
- Parameters:
n (
int
) – The index of the Fibonacci number to calculate.- Returns:
The nth Fibonacci number.
- Return type:
Examples
>>> naive(0) 0 >>> naive(1) 1 >>> naive(2) 1 >>> naive(3) 2 >>> naive(4) 3