Skip to content

Commit

Permalink
add solution for tribonacci sequence challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaiMurillo committed Jan 2, 2025
1 parent d7fcd9e commit 912afb9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions solutions/the_tribonacci_sequence/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def tribonacci(n: int) -> int:
"""
Calculate the nth tribonacci number.
Args:
n (int): Index of the tribonacci number to calculate.
Returns:
int: The nth tribonacci number.
Created on 1/01/2025
Author: Ana Isabel Murillo
"""
if n == 0:
return 0
elif n == 1 or n == 2:
return 1

a, b, c = 0, 1, 1

for _ in range(3, n + 1):
a, b, c = b, c, a + b + c

return c

0 comments on commit 912afb9

Please sign in to comment.