#233 · Dynamic programming · Beginner · 30 XP · about 5 min
The tribonacci numbers start 0, 1, 1, and every number after that is the sum of the three numbers right before it: 0, 1, 1, 2, 4, 7, 13, 24, 44, and so on.
Write tribonacci(n) that returns the number at position n, counting positions from 0. So tribonacci(0) is 0, tribonacci(1) and tribonacci(2) are both 1, and tribonacci(3) is 0 + 1 + 1 = 2.
tribonacci(4) # returns 4 tribonacci(7) # returns 24 tribonacci(10) # returns 149
0 <= n <= 100Positions go up to 100, so your function has to be quick for big positions too. Python integers have no size limit, so the answer is always exact.
First solves only, ranked by stars and then time.