Golomb sequence calculator
Get any term of Golomb’s sequence: the 10th term is 5 and the 20th is 8. The sequence 1, 2, 2, 3, 3, 4, 4, 4… lists each value as many times as its own term says, useful for worksheets and contest checks. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 10
- Term
- 5
Golomb's self-describing sequence is a classic integer sequence in which each term both continues the sequence and counts how many times its own index value appears later. With seed a of one equal to one, every larger index obeys the recurrence a of n equals one plus a of n minus a of a of n minus one. The sequence begins one, two, two, three, three, four, four, four, five, five, five, and continues so that the value k appears exactly a of k times.
What Golomb's self-describing sequence is and how the recurrence works
Solomon Golomb introduced a non-decreasing sequence of positive integers that describes its own run lengths: the value one appears once, two appears twice, three appears three times is false—instead three appears a of three times, and so on. Formally the classical definition sets a of one equal to one and, for every integer n greater than one, a of n equal to one plus a of n minus a of a of n minus one.
Unrolling the first steps yields two, two, three, three, four, four, four, five, five, five, six, six, six, six, and so on. The self-describing property is that for every positive integer k, the number of indices n with a of n equal to k is exactly a of k. The sequence is catalogued as OEIS A001462 under the one-based indexing used here.
Practical tips, limits, and where the Golomb sequence fits
Students meet Golomb's sequence when studying self-describing integer sequences, when comparing recursive definitions that look up earlier terms through nested indices, and when exploring how a simple local rule can encode global run-length structure without an explicit construction table. Teachers can generate answer keys for worksheets that ask for a of a given n without trusting opaque calculator apps that hide the seed or use a different offset convention.
Developers use the same contract to validate sample data for number-theory libraries, to seed property tests, or to pre-compute expected terms before a demonstration step. Contest practice often needs a fast offline source of Golomb answers so solutions can be checked without downloading OEIS tables under time pressure. Do not confuse one-based a of one equals one with zero-based table shifts used in some code samples—always check the definition field before grading against a different convention.
What you can do with it
Homework and contest a(n) checks
Compute the n-th Golomb term for worksheets and contest validators without manual recurrence tables or ad-hoc scripts.
Teaching self-describing sequences
Show students how a nested index recurrence encodes its own run lengths while they change n live in the browser at no cost.
FAQ
What does the Golomb sequence calculator cost?
It is free in your browser on this page.
What happens if n is below 1?
Golomb's self-describing sequence is defined here only for positive integers n ≥ 1.
How is a(n) computed?
The seed is a(1)=1. For each k from 2 to n the engine sets a(k)=1+a(k−a(a(k−1))) using a bottom-up integer array. The same n always yields the same term.
What are some known values?
a(1)=1, a(2)=2, a(3)=2, a(4)=3, a(5)=3, a(6)=4, a(10)=5, a(20)=8. The sequence is OEIS A001462 under this 1-based indexing.
How many times does each value appear in the Golomb sequence?
Each value k appears exactly a(k) times. For example, the 4th term is 3, so the value 4 appears three times: 4, 4, 4. That self-counting rule is what makes the sequence self-describing.
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/golomb-sequence \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":10}'const res = await fetch("https://api.kit.forhosting.com/numth/golomb-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/golomb-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/golomb-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/golomb-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.golomb_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.
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
Send n at least one; values below one fail validation with a clear invalid_input message and are never charged.
What Golomb's self-describing sequence is and how the recurrence works
When you only need a single term, send the index n; the response echoes n, the value term equal to a of n, a short formula string, and a definition summary that documents the seed, the recurrence, and the self-describing property so graders and students can recompute small cases by hand and match the API line by line without ambiguity about indexing conventions or off-by-one table shifts found in some programming blogs.
How to call the API and what the response contains
A successful response includes n as echoed, term equal to a of n, formula equal to the compact string a of n equals one plus a of n minus a of a of n minus one, and definition documenting a of one equals one, the rule for n greater than one, and the self-describing count property. Prefer paired classroom examples such as n equals one yielding one, n equals ten yielding five, n equals twenty yielding eight, and a zero or negative n demonstrating the hard rejection path. Send a JSON body with a single required field n: a positive whole number at least one and at most one hundred thousand, the one-based index of the Golomb term you want. Aliases index, order, and term are accepted for the same meaning so forms, spreadsheets, and query strings can reuse one contract. Failed validation—a missing n, a non-integer, a fraction, scientific notation, a value above the published limit, or any n below one—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item.
Practical tips, limits, and where the Golomb sequence fits
On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. Pair this landing with Fibonacci, Hofstadter Q, Collatz, Padovan, and other sequence tools when you are building a small recreational number-theory lab of free, deterministic endpoints.
Integration use cases
Deterministic test fixtures
Generate reproducible Golomb values for unit tests, property checks, and CI assertions that fix known indices and expected terms.
Technical questions
Is the algorithm randomized?
No. It uses deterministic integer arithmetic only. There is no network, no Date, and no Math.random.