Kolakoski walks

kolakoski_walks_gif

The Kolakoski sequence

The Kolakoski sequence is a list of 1's and 2's. Each number can appear alone in a block of one, or next to another copy of the same number in a block of two. For example, a block of one 1 is "1" and a block of two 1's is "11".

The Kolakoski sequence is constructed so that the numbers in the sequence describe the lengths of the blocks in the sequence.

The sequence begins as follows:

1 2 2 1 1 2 1 ...

These first seven numbers can be described as a block of one 1, followed by a block of two 2's, followed by a block of two 1's, followed by a block of one 2, followed by a block of one 1:

1 22 11 2 1 ...

The lengths of each of those blocks, in order, are: one, two, two, one, one, or:

1 2 2 1 1 ...

which you may recognize as the start of the Kolakoski sequence.

The sequence creates itself by describing itself.

At the beginning of the pandemic, I started going on “random Kolakoski walks.” I walked 1 or 2 blocks according to the Kolakoski sequence, then turned randomly and repeated. The images above show possible random Kolakoski walk routes on a grid.

kolakoski_ArrayPlots

These are array plots of iterations of the Kolakoski sequence whose numbers of terms are perfect squares, which lend themselves well to square-shaped visualizations. The variations in pattern and randomness become evident as more terms are displayed from top left to bottom right. Click here to see the code