login
Differential variant of the Kolakoski sequence, with initial terms 1, 1.
1

%I #19 Dec 02 2018 02:39:53

%S 1,1,2,2,2,1,2,2,2,1,1,1,2,1,1,1,2,2,1,1,1,2,2,1,1,1,2,1,1,2,2,1,2,2,

%T 2,1,1,2,2,2,1,1,2,1,1,1,2,2,2,1,2,2,2,1,1,2,1,1,1,2,1,1,2,2,2,1,1,2,

%U 2,2,1,2,2,2,1,1,1,2,1,1,1,2,2,1,2,2,1

%N Differential variant of the Kolakoski sequence, with initial terms 1, 1.

%C Conjecture: the density of 1's is equal to 1/2.

%C 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).

%C 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.

%C +------+-------------------------------------------------------------------

%C | a(n) | 1 1 2 2 2 1 2 2 2 1 1 1 2 1 1 1 2

%C +------+-------------------------------------------------------------------

%C | D(n) | 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1

%C +------+-------------------------------------------------------------------

%C \-----/ \-----/ \-----/ \-----/ \-----/ \-----/

%C | a(n) | 1 1 2 2 2 1 2 2 2 1

%C -------+------------------------------------------------------------------

%H Andrey Zabolotskiy, <a href="/A294647/b294647.txt">Table of n, a(n) for n = 1..20000</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Kolakoski_sequence">Kolakoski sequence</a>

%p nn:=100:a:=array(1..151):d:=array(1..151):

%p a[1]:=1:a[2]:=1:a[3]:=2:d[1]:=0:d[2]:=1:d[3]:=0:j:=2:

%p for n from 3 to nn-1 do:

%p if a[n]= 2 and d[j]=1

%p then

%p j:=j+1:d[j]:=0:j:=j+1:d[j]:=0:

%p else

%p if a[n]= 2 and d[j]=0

%p then

%p j:=j+1:d[j]:=1:j:=j+1:d[j]:=1:

%p else

%p if a[n]=1 and d[j]=1

%p then

%p j:=j+1:d[j]:=0:

%p else

%p if a[n]=1 and d[j]=0

%p then

%p j:=j+1:d[j]:=1:

%p else

%p fi:fi:fi:fi:

%p for k from 1 to j do:

%p s:=a[k]+d[k]:

%p if s=3 then

%p a[k+1]:=1:

%p else

%p a[k+1]:=s:fi:

%p od:od:

%p print(a):print(d):

%o (Python)

%o a = [1]

%o for n in range(100):

%o a += [3-a[-1] if n%2 else a[-1], a[-1]][:a[n]]

%o print(a)

%o # _Andrey Zabolotskiy_, Nov 20 2017

%Y Cf. A000002.

%K nonn

%O 1,3

%A _Michel Lagneau_, Nov 06 2017