We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 788d95b commit 76529e1Copy full SHA for 76529e1
maths/tribonacci.py
@@ -0,0 +1,21 @@
1
+"""
2
+This program calculates the "Nth Tribonacci number in a series.
3
+
4
+The Tribonacci sequence Tn is defined as follows :-
5
6
+T(0) = 0; T(1) = 1; T(2) = 1; and T(n+3) = T(n) + T(n+1) + T(n+3) for n>=0
7
8
+In this program, we assume an integer 'n' is given and we have to calculate nth Tribinacci number
9
10
11
12
+def tribonacci(self, n : int) -> int :
13
+ trib = [0,1,1]
14
+ for i in range(3,n+1):
15
+ x = trib[i-1] + trib[i-2] + trib[i-3]
16
+ trib.append(x)
17
+ return trib[n]
18
19
20
+if __name__ == "__main__" :
21
+ print(tribonacci(25)) #prints 1389537
0 commit comments