maths.padovan_sequence

Functions

padovan_sequence(→ int)

Return the n-th term of the Padovan Sequence.

Module Contents

maths.padovan_sequence.padovan_sequence(n: int) int

Return the n-th term of the Padovan Sequence. The Padovan sequence is the sequence of integers P(n) defined by the initial values P(0) = P(1) = P(2) = 1 and the recurrence relation P(n) = P(n-2) + P(n-3).

https://en.wikipedia.org/wiki/Padovan_sequence

Parameters:

n – The index of the term to return.

Returns:

The n-th term of the Padovan Sequence.

>>> padovan_sequence(0)
1
>>> padovan_sequence(1)
1
>>> padovan_sequence(2)
1
>>> padovan_sequence(3)
2
>>> padovan_sequence(4)
2
>>> padovan_sequence(5)
3
>>> padovan_sequence(10)
12
>>> padovan_sequence(-1)
Traceback (most recent call last):
    ...
ValueError: Input must be a non-negative integer.