MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / tribonacci

Function tribonacci

dynamic_programming/tribonacci.py:4–18  ·  view source on GitHub ↗

Given a number, return first n Tribonacci Numbers. >>> tribonacci(5) [0, 0, 1, 1, 2] >>> tribonacci(8) [0, 0, 1, 1, 2, 4, 7, 13]

(num: int)

Source from the content-addressed store, hash-verified

2
3
4def tribonacci(num: int) -> list[int]:
5 """
6 Given a number, return first n Tribonacci Numbers.
7 >>> tribonacci(5)
8 [0, 0, 1, 1, 2]
9 >>> tribonacci(8)
10 [0, 0, 1, 1, 2, 4, 7, 13]
11 """
12 dp = [0] * num
13 dp[2] = 1
14
15 for i in range(3, num):
16 dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]
17
18 return dp
19
20
21if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected