Tribonacci Calculator

Generate the Tribonacci sequence and generalized variants with custom starting values.

TribonacciCalculator.tribConst
1.8392867552
TribonacciCalculator.ratioLabel (T20/T19)
1.8392873975

TribonacciCalculator.sequenceLabel

nTribonacciCalculator.tribLabel
00
10
21
31
42
54
67
713
824
944
1081
11149
12274
13504
14927
151705
163136
175768
1810609
1919513

About Tribonacci

Each term is the sum of the three preceding terms. The ratio of consecutive terms converges to the Tribonacci constant ~1.8392867552141612.

์ž์ฃผ ๋ฌป๋Š” ์งˆ๋ฌธ

์ฝ”๋“œ ๊ตฌํ˜„

from decimal import Decimal

def tribonacci(n: int, a: int = 0, b: int = 0, c: int = 1) -> list[int]:
    """Generate the first n terms of the Tribonacci sequence."""
    if n <= 0:
        return []
    seq = [a, b, c]
    while len(seq) < n:
        seq.append(seq[-1] + seq[-2] + seq[-3])
    return seq[:n]

# Standard Tribonacci sequence
seq = tribonacci(20)
print("Tribonacci sequence (first 20 terms):")
print(seq)

# Show ratios converging to Tribonacci constant (~1.8392867552141612)
print("\nRatios (approaching Tribonacci constant):")
for i in range(5, 20):
    ratio = seq[i] / seq[i-1] if seq[i-1] != 0 else 0
    print(f"T({i})/T({i-1}) = {seq[i]}/{seq[i-1]} โ‰ˆ {ratio:.10f}")

# Custom starting values
custom = tribonacci(15, a=1, b=1, c=2)
print("\nCustom (1,1,2):", custom)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.