Perrin sequence term
Get any term of the Perrin sequence, which starts 3, 0, 2 and adds the terms two and three places back: P(10) is 17, that is 10 plus 7. Indices run from 0 to 130. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 10
- Perrin
- 17
- Recurrence
- P(0)=3; P(1)=0; P(2)=2; P(n)=P(n-2)+P(n-3) for n>2
The Perrin sequence begins with three, zero, and two, then builds every later term by adding the values two and three places back. This calculator returns the term at a zero-based index n, together with the exact convention used for the initial values and recurrence. It is useful when checking discrete mathematics exercises, testing sequence code, or comparing recurrences that look similar but start differently. Computation is deterministic, uses integer addition only, and runs without network access, random values, or time-dependent behavior. Negative indices are rejected instead of being silently reinterpreted.
Understand the Perrin sequence convention
This capability uses the classical zero-based Perrin definition: P(0) is 3, P(1) is 0, and P(2) is 2. For every index greater than two, P(n) equals P(n-2) plus P(n-3). The first terms are therefore 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, and 22.
Notice that the recurrence has the same lag pattern as the Padovan sequence, but the initial values differ. That distinction matters because identical recurrence rules can produce completely different terms when their seeds change. The response includes both a compact formula and the full seed statement so the convention is never hidden.
Indexing begins at zero, which means an input of zero returns 3 rather than the first computed recurrence step. The operation returns one requested term, not an array containing every earlier term.
Send an index and read the result
Provide n as a non-negative whole number from zero through 130. A successful result echoes the normalized index in n, places the requested integer in perrin, and supplies formula and recurrence fields that describe how it was obtained. For example, n equal to 10 returns the Perrin value 17 because P(10) is P(8) plus P(7), or 10 plus 7.
Text entered through the browser control may contain an unsigned integer, but fractions, scientific notation, blank input, and unrelated text are rejected rather than rounded or guessed. The computation uses a rolling window of three terms, so it requires constant memory and performs at most 128 additions.
Use the value in lessons, tests, and algorithms
Perrin terms are useful for teaching recurrence relations because the rule is short while the nonstandard seeds expose careless assumptions. In a classroom, compare the returned formula with a student's handwritten expansion and verify the base cases before checking later arithmetic. If your application needs very large terms, use a BigInt-oriented implementation with a clearly documented string output.
For ordinary educational and validation work, the bounded integer response is easier to inspect, serialize, and compare across environments.
What you can do with it
Check a recurrence exercise
Verify a student's n-th Perrin term while keeping the initial values and lag-two-plus-lag-three rule visible in the response.
Compare Perrin and Padovan numbers
Demonstrate how different seeds change a sequence even when two definitions use the same recurrence pattern.
FAQ
What are the first Perrin numbers?
Using zero-based indexing, they begin 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, and 22.
Which recurrence does this calculator use?
It uses P(0)=3, P(1)=0, P(2)=2, followed by P(n)=P(n-2)+P(n-3) for n greater than 2.
What is P(10) in the Perrin sequence?
P(10) is 17. It is the sum of P(8), which is 10, and P(7), which is 7: the terms two and three places before it.
How is the Perrin sequence different from Padovan's?
Both use the same rule, adding the terms two and three places back, but they start from different values. Perrin starts 3, 0, 2, so the terms that follow are completely different.
What is the largest index I can use?
Any whole index from 0 to 130. Up to that point every term stays exact. Negative indices are refused rather than reinterpreted, and the index 0 returns 3.
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/numth/perrin-sequence \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":10}'const res = await fetch("https://api.kit.forhosting.com/numth/perrin-sequence", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 10
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/perrin-sequence",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 10
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/perrin-sequence", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":10}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":10}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/perrin-sequence", 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": 10
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.perrin_sequence",
"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.
Limits
max_n | 130 |
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
Understand the Perrin sequence convention
Negative indices are outside this contract and produce an invalid_input error. This explicit behavior makes the calculator suitable for exercises, automated checks, and documentation where an off-by-one interpretation would otherwise be difficult to spot.
Send an index and read the result
The upper bound protects exact arithmetic: through index 130, every returned value remains within JavaScript's safe-integer range in both the browser and Worker runtime. Each successful API request costs $0.002; invalid input is reported as invalid_input and is not a valid sequence result.
Use the value in lessons, tests, and algorithms
The deterministic JSON result also works well in programming challenge graders and regression suites: assert the n and perrin fields, while retaining the recurrence text as a human-readable explanation when a test fails. This capability intentionally does not extend Perrin numbers to negative indices, return a full prefix, or approximate values beyond the exact safe-integer limit.
Integration use cases
Test a sequence implementation
Create deterministic fixtures for base cases and later indices without duplicating the reference recurrence in every test harness.
Technical questions
Does n start at zero or one?
It starts at zero. Therefore n=0 returns 3, n=1 returns 0, and n=2 returns 2.
What happens when n is negative?
The request fails with invalid_input because this capability supports only the classical non-negative Perrin sequence.
How much does an API request cost?
A successful API request costs $0.002. The same deterministic calculation is also available in the free browser runner.