# Kyu 6
"""
Question:
As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the 
sequence to generate the next. 
So, if we are to start our Tribonacci sequence with [1, 1, 1] as a starting input (AKA signature), we have this sequence:

[1, 1 ,1, 3, 5, 9, 17, 31, ...]

"""

# my solution
def tribonacci(signature, n):
    trilist = signature[:n]
    for i in range(n - len(trilist)):
        trilist.append(sum(trilist[i : len(trilist)]))
    return trilist


print(tribonacci([1, 1, 1], 10))

# Expected [1, 1, 1, 3, 5, 9, 17, 31, 57, 105]


# codewars
def tribonacci(signature, n):
    res = signature[:n]
    for i in range(n - 3):
        res.append(sum(res[-3:]))
    return res


# sum(res[-3:]) will capture last 3 elements and take their sum
