Kolakoski Sequence Calculator

Sequences

Kolakoski value a(20)1
ones among the first 20 terms10
twos among the first 20 terms10
share of ones so far50.00%
How this was calculated
  1. The Kolakoski (Oldenburger-Kolakoski) sequence is built from runs of 1s and 2s whose lengths are dictated by the sequence itself: it is its own run-length encoding.
  2. Start with 1, 2, 2: the third term says the second run has length 2, the fourth term will fix the third run, and so on, alternating 1-runs and 2-runs.
  3. Generating the runs out to position 20 gives a(20) = 1, with 10 ones and 10 twos so far.
  4. Whether the density of ones settles at exactly one half is a famous open problem - the counts stay close, but nobody has proved they converge.

The Kolakoski sequence is a small miracle of self-reference: a sequence of 1s and 2s that describes its own construction. Read off the lengths of its runs - first a run of one, then a run of two, then two, then one, then one - and the numbers you read are the sequence itself.

This Kolakoski sequence calculator generates the sequence run by run: it starts 1, 2, 2 and then lets each term dictate the length of the next run, alternating between 1-runs and 2-runs. Ask for a term or for the first n terms, with the counts of ones and twos reported alongside.

The first 20 terms - 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1 - contain exactly 10 ones and 10 twos. Whether that balance is exact in the limit is one of the famous open problems of combinatorics on words: among the first 100 terms there are 49 ones and 51 twos, close to half, but nobody has proved the density of ones converges to one half.

Worked examples

The 20th term

(Value at n · 20)

Kolakoski value a(20)1
ones among the first 20 terms10
twos among the first 20 terms10
share of ones so far50.00%

The 100th term

(Value at n · 100)

Kolakoski value a(100)2
ones among the first 100 terms49
twos among the first 100 terms51
share of ones so far49.00%

First 20 terms

(First n terms · 20)

first 20 Kolakoski terms1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1
ones among the terms10
twos among the terms10
last term1

A sequence that is its own run-length encoding

Run-length encoding compresses data by recording runs: the string 111223 becomes 'three 1s, two 2s, one 3'. The Kolakoski sequence is the fixed point of this idea applied to the alphabet {1, 2}: it is a sequence whose own run lengths, read in order, reproduce the sequence. Start with 1, 2, 2. The first term (1) says the first run has length 1 - a single 1. The second term (2) says the second run has length 2 - two 2s. The third term (2) says the third run has length 2 - two 1s. And so on, forever, with the sequence always exactly as far ahead as it needs to be.

This self-consistency is why the sequence can be generated mechanically without lookahead paradoxes: when the generator needs the length of the next run, that term has already been written. The calculator implements precisely this run-by-run generation.

  • Alphabet: only 1s and 2s
  • Run lengths of the sequence = the sequence itself
  • Seed: 1, 2, 2 - then self-sustaining

Reading the first 20 terms

The first 20 terms are 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1. Group them into runs: (1)(22)(11)(2)(1)(22)(1)(22)(11)(2)(11)(22)(1) - the run lengths are 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, ... which is the sequence starting again from its own beginning. Checking this by eye once is the fastest way to understand the definition.

The counts in this prefix are perfectly balanced: 10 ones and 10 twos. The 20th term is a(20) = 1. Balance this exact is a small-prefix coincidence, but the near-balance persists: it is forced by the construction, because long runs of either symbol would require long runs in the length sequence too.

  • a(20) = 1
  • First 20 terms: 10 ones, 10 twos
  • Runs of the prefix reproduce the prefix

The density question

Does the proportion of ones tend to exactly one half? The evidence is tantalising: among the first 100 terms there are 49 ones and 51 twos - a share of 49.00% - and computations far beyond that keep the share hovering near 50%. Yet no proof exists. The difficulty is that the sequence's self-reference defeats the usual tools: it is not periodic, not automatic, and not generated by a finite-state machine.

The 100th term is a(100) = 2. If you generate the first few hundred terms with the calculator you will see the share of ones wander around one half without settling - a picture of the open problem. The sequence is OEIS A000002, one of the oldest entries in the encyclopedia, which gives some sense of how long the question has resisted attack.

  • First 100 terms: 49 ones, 51 twos (49.00% ones)
  • a(100) = 2
  • Convergence to density one half: unproved
  • OEIS A000002

Oldenburger, Kolakoski, and cousins

Rufus Oldenburger described the sequence's self-generating property first; William Kolakoski popularised it as a problem in the American Mathematical Monthly, and it now carries both names. It belongs to a family of self-describing sequences - the Golomb sequence is its closest famous relative, defined by a recurrence on how often each integer appears rather than on run lengths.

Unlike Golomb's, the Kolakoski sequence takes only two values, which makes its resistance to analysis more striking: a binary, completely deterministic, easily generated sequence whose most basic statistical property is unknown. It is a standard counterexample to the intuition that simple rules imply understood behaviour.

  • Also called the Oldenburger-Kolakoski sequence
  • Closest relative: the Golomb sequence
  • Binary and deterministic - yet statistically mysterious

Worked example: generating the first runs

Generate run by run, reading lengths from the sequence itself. The first term (1) fixes a run of one 1. The second term (2) fixes a run of two 2s: the prefix is 1, 2, 2. The third term (2) fixes a run of two 1s: 1, 2, 2, 1, 1. The fourth term (1) fixes a single 2, and the fifth term (1) a single 1: the prefix reaches 1, 2, 2, 1, 1, 2, 1. The sixth term (2) then orders two 2s, giving 1, 2, 2, 1, 1, 2, 1, 2, 2 - the listed terms, each new run's length fixed by an earlier term.

The subtle point is that the reading head and the writing head move together: the sequence is always at least as long as the number of runs consumed, so the rule never asks for a term that does not exist yet. That is what makes the fixed point constructive rather than paradoxical.

  • Seed 1, 2, 2, then self-sustaining
  • Reading head never overtakes the writing head
  • Each run's length was fixed by an earlier term

What is known and what is not

Known: the sequence is not eventually periodic; it is cube-free in a suitable sense studied by several authors; and the frequency of either symbol, if the limits exist, must be one half by symmetry of the construction. Not known: whether those frequency limits exist at all. The statement 'the density of ones is one half' is therefore two conjectures wearing one coat - existence, and the value.

The calculator's counts let you watch the evidence accumulate: 10 of 20 at n = 20 (exactly half), 49 of 100 at n = 100 (49.00%). The deviations do not obviously shrink like random noise, which is part of the sequence's fascination - it is deterministic, yet its statistics behave like an unsolved random process.

  • Not eventually periodic
  • Density one half: conjectured, unproved
  • Evidence: 10/20, then 49/100

Kolakoski versus Golomb

The Golomb sequence is the Kolakoski sequence's closest famous relative, and comparing them sharpens both definitions. Golomb's sequence is non-decreasing, lists each integer k exactly a(k) times, and is defined by a recurrence reaching back a variable distance. Kolakoski's is binary, defined by runs, and has no recurrence of fixed form at all - its next term depends on the whole run structure generated so far.

Their open problems differ in kind. Golomb's sequence is comparatively well understood asymptotically; Kolakoski's resists even its first-order statistic, the density of ones. That a sequence generated by such a short rule - seed 1, 2, 2 and one sentence of instruction - can withhold so basic a fact is why it remains a benchmark for the limits of sequence analysis, and why generating its terms, as this page does to n = 500, is easy while saying anything proven about them is hard.

  • Golomb: self-referential counts, non-decreasing
  • Kolakoski: self-referential run lengths, binary
  • Generation is trivial; proof is the hard part

Using the calculator

Value mode reports a(n) with the counts of ones and twos among the first n terms and the share of ones so far - the density evidence, live. List mode prints the first n terms with their counts. Terms up to n = 500 are supported; generation is linear, one pass, run by run.

Try comparing the share of ones at n = 20 (50.00%), n = 100 (49.00%) and a few hundred: the wobble around one half, never obviously dying out, is the open problem made visible.

  • Value mode: term plus ones/twos counts and share
  • List mode up to n = 500
  • One-pass run-by-run generation

FAQs

What are the first terms of the Kolakoski sequence?

1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1 - the first 20 terms contain exactly 10 ones and 10 twos.

How is the Kolakoski sequence generated?

Start with 1, 2, 2 and let each term fix the length of the next run, alternating 1-runs and 2-runs. The sequence is its own run-length encoding.

What is the 100th Kolakoski term?

a(100) = 2. Among the first 100 terms there are 49 ones and 51 twos.

Is the density of ones exactly one half?

Unknown. The counts stay close to even - 49 ones in the first 100 terms - but convergence to exactly one half has never been proved.

Why is the sequence called self-describing?

Because reading off the lengths of its runs returns the sequence itself: it is a fixed point of run-length encoding on the alphabet {1, 2}.

Who invented the Kolakoski sequence?

Rufus Oldenburger described it first and William Kolakoski popularised it; it is often called the Oldenburger-Kolakoski sequence. It is OEIS A000002.

Sources

Related calculators

Thue-Morse Sequence Calculator
Compute Thue-Morse values t(n) from the parity of the binary digit sum - a single term or the first n terms of the overlap-free sequence.
Paperfolding Sequence Calculator
Compute the regular paperfolding sequence - the valley and mountain folds of a repeatedly folded strip, and the turn sequence of the dragon curve.
Baum-Sweet Sequence Calculator
Compute Baum-Sweet values: b(n) is 1 when the binary form of n has no zero block of odd length, and 0 when it does.