OFFSET
1,3
COMMENTS
Conjecture: the density of 1's is equal to 1/2.
The differential Kolakoski sequence a(n) starting with 1, 1, 2, 2, 2, 1, 2, ... is an infinite sequence of numbers {1, 2} such that the sequence D(n) = |a(n+1) - a(n)| = 0, 1, 0, 0, 1, 1, ... of numbers {0, 1} generates, by taking run lengths of its terms, the initial sequence a(n).
To construct the sequence, start with the pair of digits (a(1), a(2)) = (1, 1) that generates D(1) = a(2) - a(1) = 0. The first run in D of length a(1) = 1 consists of just that single 0, so the next term in D should be 1. Therefore, require that the next run in D to consist only of a(3) - a(2) = 1, giving 01 as the initial part of D. The following run is a(4) - a(3), a(5) - a(4) = 00 with two identical digits, having length 2. So, the first three terms of the sequence are 1, 1, 2.
+------+-------------------------------------------------------------------
| a(n) | 1 1 2 2 2 1 2 2 2 1 1 1 2 1 1 1 2
+------+-------------------------------------------------------------------
| D(n) | 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1
+------+-------------------------------------------------------------------
\-----/ \-----/ \-----/ \-----/ \-----/ \-----/
| a(n) | 1 1 2 2 2 1 2 2 2 1
-------+------------------------------------------------------------------
LINKS
Andrey Zabolotskiy, Table of n, a(n) for n = 1..20000
Wikipedia, Kolakoski sequence
MAPLE
nn:=100:a:=array(1..151):d:=array(1..151):
a[1]:=1:a[2]:=1:a[3]:=2:d[1]:=0:d[2]:=1:d[3]:=0:j:=2:
for n from 3 to nn-1 do:
if a[n]= 2 and d[j]=1
then
j:=j+1:d[j]:=0:j:=j+1:d[j]:=0:
else
if a[n]= 2 and d[j]=0
then
j:=j+1:d[j]:=1:j:=j+1:d[j]:=1:
else
if a[n]=1 and d[j]=1
then
j:=j+1:d[j]:=0:
else
if a[n]=1 and d[j]=0
then
j:=j+1:d[j]:=1:
else
fi:fi:fi:fi:
for k from 1 to j do:
s:=a[k]+d[k]:
if s=3 then
a[k+1]:=1:
else
a[k+1]:=s:fi:
od:od:
print(a):print(d):
PROG
(Python)
a = [1]
for n in range(100):
a += [3-a[-1] if n%2 else a[-1], a[-1]][:a[n]]
print(a)
# Andrey Zabolotskiy, Nov 20 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Michel Lagneau, Nov 06 2017
STATUS
approved