Tribonacci number calculator
Position 6 of the Tribonacci sequence holds 7: each term is the sum of the three before it, starting from 0, 0 and 1. Enter a position from 0 to 40 and get its exact whole-number value, with no rounding at all. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Index n
- 0
- Tribonacci number
- 0
free
How the Tribonacci sequence is built
The Tribonacci sequence works like Fibonacci, except that each new term is the sum of the three terms before it rather than two. This calculator starts from 0, 0 and 1, so the run continues 1, 2, 4, 7, 13, 24, 44, 81 and 149. The ratio between neighbouring terms settles near 1.839, known as the Tribonacci constant, so the values grow steadily without exploding across the supported range. Each term is reached by a single forward pass that carries the last three values along, which means the result is always an exact whole number, with no rounding at any step, from position 0 up to position 40.
Where it is used and how to avoid slips
Tribonacci numbers count certain tilings and ways of splitting a number into parts, appear in coding puzzles such as the classic exercise of finding the n-th Tribonacci number, and serve as a trusted reference when you test your own version or look up terms of the sequence catalogued as A000073. The most common slip is the position: counting starts at 0, so position 6 holds 7, not 13. Check too that your source uses the same starting values of 0, 0 and 1. Positions must be whole numbers from 0 to 40; at 40 the term is about 39 billion and still exact.
The Tribonacci recurrence and sequence
The Tribonacci sequence generalizes Fibonacci by summing the previous three terms instead of two: T(n) = T(n-1) + T(n-2) + T(n-3). This capability uses the seeds T(0)=0, T(1)=0, T(2)=1, so the run begins 0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, and continues from there. The ratio of successive terms approaches the Tribonacci constant, roughly 1.839, so the values grow steadily but stay modest across the supported range.
There is no rounding and no floating point in the result: every value is an exact integer, which is what makes this useful as an oracle rather than an approximation.
Input validation and the range limit
The only input is n, and it is validated strictly. The upper bound of 40 is deliberate: it keeps every result an exact JavaScript safe integer. T(40) is about 3.9e10 (roughly 39 billion), comfortably below Number.MAX_SAFE_INTEGER at about 9.0e15, so no precision is lost and no BigInt is needed.
What you can do with it
Sequence lookup and verification
Generate or check terms of the Tribonacci sequence (OEIS A000073) against an exact, deterministic reference.
Coding puzzles and interview prep
Use it as a trusted oracle for Tribonacci implementations, such as the classic N-th Tribonacci number exercise.
Combinatorics and procedural generation
Tribonacci numbers count certain tilings and compositions; pull exact terms to use as coefficients or growth counts.
FAQ
What seeds and rule does it use?
Seeds T(0)=0, T(1)=0, T(2)=1, then each term is the sum of the previous three: T(n)=T(n-1)+T(n-2)+T(n-3). The sequence is 0, 0, 1, 1, 2, 4, 7, 13, 24, 44, ...
Why is n capped at 40?
To keep every result an exact safe integer. T(40) is about 3.9e10, well under 2^53, so no rounding or BigInt is required.
Is the result exact?
Yes. It is pure integer arithmetic with no floating point and no rounding, so the same n always returns the same value.
Does the Tribonacci sequence start counting at 0 or at 1?
At 0. Positions 0, 1 and 2 hold the starting values 0, 0 and 1, so position 6 holds 7 and position 7 holds 13. Positions run from 0 up to 40.
How is Tribonacci different from Fibonacci?
A Fibonacci term adds the two terms before it; a Tribonacci term adds three. From the starting values 0, 0 and 1 the run goes 1, 2, 4, 7, 13, and the ratio between neighbouring terms settles near 1.839.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/tribonacci-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":6}'const res = await fetch("https://api.kit.forhosting.com/math/tribonacci-number", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 6
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/tribonacci-number",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 6
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/tribonacci-number", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":6}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":6}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/tribonacci-number", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 6
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.tribonacci_number",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Returns the exact nth Tribonacci number — the sequence in which each term is the sum of the previous three, T(n)=T(n-1)+T(n-2)+T(n-3), seeded with T(0)=0, T(1)=0, T(2)=1 — for any integer n from 0 to 40, as {n, value} JSON.
The Tribonacci recurrence and sequence
Given the single input n it returns {n, value}, where value is the exact nth term; for example n=6 yields 7 and n=0 yields 0.
Input validation and the range limit
It must be an integer, non-negative, and no greater than 40; anything else — a fraction, a negative value, a non-number, or n=41 — throws a typed invalid_input error tied to that single field so a form can attach the message to it. The three base cases (n=0, n=1, n=2) are returned directly; for any larger n the term is built up iteratively rather than recursively, which avoids the exponential call-tree blow-up that a naive triple-recursive definition would suffer.
Algorithm, determinism and where it runs
Computation is a single forward loop that carries three rolling variables and advances them until it reaches n, so the work is linear in n and finishes in microseconds even at the maximum of 40. The output is a compact {n, value} object with no extra fields to strip. Failed API tasks are never charged; prepaid KIT balance is debited only for successful calls at the base price of $0.002.
Technical questions
What happens with invalid n?
A non-integer, a negative value, or n greater than 40 returns a typed invalid_input error tied to the single field n.
Is it free?
The browser widget is free (tier A, on-device). The API is $0.002 per successful task, and failed calls are not billed.