Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions maths/tribonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
This program calculates the "Nth Tribonacci number in a series.

The Tribonacci sequence Tn is defined as follows :-

T(0) = 0; T(1) = 1; T(2) = 1; and T(n+3) = T(n) + T(n+1) + T(n+3) for n>=0

In this program, we assume an integer 'n' is given and
we have to calculate nth Tribinacci number

"""

def tribonacci(n : int) -> int :
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/tribonacci.py, please provide doctest for the function tribonacci

Please provide descriptive name for the parameter: n

trib = [0,1,1]
for i in range(3,n+1):
x = trib[i-1] + trib[i-2] + trib[i-3]
trib.append(x)
return trib[n]


if __name__ == "__main__" :
import doctest
doctest.testmod()