Nilsson algorithm for the Kolakoski sequence
ID: nilsson-algorithm-for-the-kolakoski-sequence
This algorithm is more efficient in space, using only , as it recursively compresses the state required to keep track of what to do next.
Time is still .
The table at maths-people.anu.edu.au/~brent/pd/Kolakoski-UNSW.pdf page 20 has a summary image, but it is hard to understand.
1 2(0) 1(1)The starting state is:which means that it implicitly contains infinitely many The actual algorithm will of course omit as many trailing
2 | 2 2(1) 2(1) 2(1) 2(1) ...2(1) at the end which we abbreviate just as:2 | 2 2(1) ...2(1) as it can.The update rules are:Note that both rules don't overlap so that each update is always determined by only one of them at a time.
- go left to right:
- flip:continue going left to right.
x(0) y(0) !x((!x)-1) unchanged - repeat:and then stop further updates.
x(0) y(n > 0) x(x-1) y(n - 1)
- flip:
Also the first column is always implicitly
(0).2 | 2 2(1) ...
3 | 2 2(0) 2(1) ...Here we:
2 | 2 2(1) ...
3 | 2 2(0) 2(1) ...
4 | 1 2(1) 2(0) 2(1) ...2 | 2 2(1) ...
3 | 2 2(0) 2(1) ...
4 | 1 2(1) 2(0) 2(1) ...
5 | 1 2(0) 2(1) 2(0) 2(1) ... 2 | 2 2(1) ...
3 | 2 2(0) 2(1) ...
4 | 1 2(1) 2(0) 2(1) ...
5 | 1 2(0) 2(0) 2(1) ...
6 | 2 1(0) 2(1) 2(0) 2(1) ...
7 | 1 1(0) 2(0) 2(0) 2(1) ...
8 | 2 2(1) 1(0) 2(1) 2(0) 2(1) ...
9 | 2 2(0) 1(0) 2(1) 2(0) 2(1) ...
10 | 1 1(0) 1(0) 2(0) 2(0) 2(1) ...
11 | 2 2(1) 2(1) 1(0) 2(1) 2(0) 2(1) ...
12 | 2 2(0) 2(1) 1(0) 2(1) 2(0) 2(1) ...
13 | 1 2(1) 2(0) 1(0) 2(1) 2(0) 2(1) ...
14 | 1 2(0) 2(0) 1(0) 2(1) 2(0) 2(1) ...
15 | 2 1(0) 1(0) 1(0) 2(0) 2(0) 2(1) ...
16 | 1 2(1) 2(1) 2(1) 1(0) 2(1) 2(0) 2(1) ... New to topics? Read the docs here!