login
Number of 1's in n-th string when A000002 is expressed as 1,2,2,11,21,221,22112,11221211,21221121121,2212211212212112,
0

%I #45 Aug 13 2020 21:53:44

%S 0,2,1,1,2,5,6,7,12,19,29,43,62,95,148,216,322,482,727,1083,1627,2457,

%T 3660,5518,8250,12403,18594,27914,41863,62781,94158,141205,211797,

%U 317782,476743,714948,1072526,1608732,2413223,5428986

%N Number of 1's in n-th string when A000002 is expressed as 1,2,2,11,21,221,22112,11221211,21221121121,2212211212212112,

%C Representing A000002 as a tree. Each branch of this tree is a string. Starting from n=3, each 1 in n-th string generates either 1 or 2 in (n+1)-th string and each 2 in n-th string generates either 11 or 22 in (n+1)-st string based on the previously generated term of either 2 or 1. Hence number of terms in (n+1)-st string is sum of all terms in n-th string.

%o (Python)

%o MAX_NUM = 10000 # Number of terms in Kolakoski Sequence

%o K = [1,2,2]

%o previous = 2

%o # Generate Kolakoski Sequence

%o for index1 in range(2,MAX_NUM):

%o generator = K[index1]

%o if (generator == 1 and previous == 1):

%o K.append(2)

%o previous = 2

%o elif(generator == 2 and previous == 1):

%o K.append(2)

%o K.append(2)

%o previous = 2

%o elif(generator == 1 and previous == 2):

%o K.append(1)

%o previous = 1

%o elif(generator == 2 and previous == 2):

%o K.append(1)

%o K.append(1)

%o previous = 1

%o branch_sum = 1

%o index2 = 2

%o cntr1 = 1

%o while(index2 < MAX_NUM):

%o ones_cntr = 0

%o # This for loop extracts strings from Kolakoski Sequence

%o start_index = index2

%o end_index = index2 + branch_sum

%o branch_sum = 0

%o for index3 in range(start_index , end_index):

%o branch_sum = branch_sum + K[index3]

%o ones_cntr = ones_cntr + (K[index3]%2)

%o index2 = end_index

%o print(str(cntr1)+" "+str(ones_cntr)+"\n")

%o cntr1 = cntr1 + 1

%Y Cf. A000002.

%K nonn

%O 3,2

%A _Rakesh Khanna A_, May 24 2020