跳到内容
🛠️ToolsShed

Tribonacci Calculator

生成Tribonacci序列和带有自定义起始值的泛化变体。

特里波那契常数
1.8392867552
比率 (T20/T19)
1.8392873975

数列

n特里波那契
00
10
21
31
42
54
67
713
824
944
1081
11149
12274
13504
14927
151705
163136
175768
1810609
1919513

关于特里波那契

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

关于此工具

特里波那契数列是著名斐波那契数列的推广,其中每个数是前三个数的和,而不是前两个数的和。与斐波那契数列一样,它出现在自然界、数学和算法分析中,是研究递归模式和数学增长的宝贵工具。这个计算器让你可以快速探索特里波那契数列,而无需手工计算或编写代码。

要使用计算器,输入所需的数列长度,并可选择自定义前三个起始值(默认为0、0和1)。点击生成,工具将在几秒内显示完整的数列。你还可以将结果复制到剪贴板,用于电子表格、文档或编程项目。这对学习递归数列的学生、实现算法挑战的开发者或对探索数学模式感兴趣的任何人特别有帮助。

常见问题

代码实现

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.