Generate Kolakoski Sequence

Generate the Kolakoski sequence — a self-describing sequence of 1s and 2s where the run lengths are described by the sequence itself: 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, ...

Options
Kolakoski Sequence Options
Starting index for the Kolakoski sequence.
How many elements to generate?
Delimiter among sequence elements.
(Newline by default.)
Output (Kolakoski Sequence)

What It Does

Generate the Kolakoski sequence — a self-describing sequence of 1s and 2s where the run lengths are described by the sequence itself: 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, ...

How It Works

Generate Kolakoski Sequence produces new output from rules, parameters, or patterns instead of editing an existing document. That makes input settings more important than input text, because the settings are what define the shape of the result.

Generators are only as useful as the settings behind them. When the output seems off, check the count, range, delimiter, seed values, or pattern options before judging the result itself.

All processing happens in your browser, so your input stays on your device during the transformation.

Common Use Cases

  • Study self-referential sequences
  • Research open problems about the Kolakoski sequence density
  • Explore combinatorics on words
  • Generate test data for sequence analysis algorithms
  • Educational exploration of recursive definitions

How to Use

  1. Specify term count.
  2. Click Generate.
  3. View sequence with run-length annotation.
  4. Copy.

Features

  • Generates the Kolakoski sequence
  • Shows run-length decomposition
  • Highlights the self-describing property
  • Large sequence support
  • Density statistics

Examples

Below is a representative input and output so you can see the transformation clearly.

Input
n: 10
Output
1 2 2 1 1 2 1 2 2 1

Edge Cases

  • Very large inputs can still stress the browser, especially when the tool is working across many numbers. Split huge jobs into smaller batches if the page becomes sluggish.
  • Empty or whitespace-only input is technically valid but may produce unchanged output, which can look like a failure at first glance.
  • If the output looks wrong, compare the exact input and option values first, because Generate Kolakoski Sequence should be repeatable with the same settings.

Troubleshooting

  • Unexpected output often means the input is being split or interpreted at the wrong unit. For Generate Kolakoski Sequence, that unit is usually numbers.
  • If a previous run looked different, check for hidden whitespace, changed separators, or a setting that was toggled accidentally.
  • If nothing changes, confirm that the input actually contains the pattern or structure this tool operates on.
  • If the page feels slow, reduce the input size and test a smaller sample first.

Tips

The Kolakoski sequence is unique: it is the only sequence (up to the choice of starting with 1 or 2) that describes its own run lengths.

The Kolakoski Sequence

The Kolakoski sequence K = 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, ... has a remarkable self-referential property: the lengths of consecutive runs of identical digits ARE the sequence itself. Runs: 1, 22, 11, 2, 1, 22, 1, 22, 11, 2, .... Run lengths: 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, ... = K.

Open Problems

It is conjectured that 1s and 2s appear with equal density (each approaching 50%), but this has never been proven. The Kolakoski sequence has resisted analysis despite decades of research.

Frequently Asked Questions

What makes this sequence self-describing?

Reading the run lengths (how many consecutive identical digits) gives back the original sequence.

Is the density of 1s equal to 1/2?

Computationally it appears so, but this is unproven — one of the major open problems about this sequence.

Who discovered it?

William Kolakoski described it in 1965, though it was known earlier.

Is it periodic?

No. The Kolakoski sequence is aperiodic.

Can it start with 2 instead of 1?

Yes. Starting with 2 gives a shifted version: 2, 2, 1, 1, 2, 1, 2, 2, 1, ....

What alphabet does it use?

Only the symbols 1 and 2. Generalizations to other alphabets exist but have different properties.