This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A334955 #47 Jun 01 2025 17:40:22 %S A334955 0,2,1,1,2,5,6,7,12,19,29,43,62,95,148,216,322,482,727,1083,1627,2457, %T A334955 3660,5518,8250,12403,18594,27914,41863,62781,94158,141205,211797, %U A334955 317782,476743,714948,1072526,1608732,2413223,5428986 %N A334955 Number of 1's in n-th string when A000002 is expressed as 1, 2, 2, 11, 21, 221, 22112, 11221211, 21221121121, 2212211212212112, .... %C A334955 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 A334955 (Python) %o A334955 MAX_NUM = 10000 # Number of terms in Kolakoski Sequence %o A334955 K = [1,2,2] %o A334955 previous = 2 %o A334955 # Generate Kolakoski Sequence %o A334955 for index1 in range(2,MAX_NUM): %o A334955 generator = K[index1] %o A334955 if (generator == 1 and previous == 1): %o A334955 K.append(2) %o A334955 previous = 2 %o A334955 elif(generator == 2 and previous == 1): %o A334955 K.append(2) %o A334955 K.append(2) %o A334955 previous = 2 %o A334955 elif(generator == 1 and previous == 2): %o A334955 K.append(1) %o A334955 previous = 1 %o A334955 elif(generator == 2 and previous == 2): %o A334955 K.append(1) %o A334955 K.append(1) %o A334955 previous = 1 %o A334955 branch_sum = 1 %o A334955 index2 = 2 %o A334955 cntr1 = 1 %o A334955 while(index2 < MAX_NUM): %o A334955 ones_cntr = 0 %o A334955 # This for loop extracts strings from Kolakoski Sequence %o A334955 start_index = index2 %o A334955 end_index = index2 + branch_sum %o A334955 branch_sum = 0 %o A334955 for index3 in range(start_index , end_index): %o A334955 branch_sum = branch_sum + K[index3] %o A334955 ones_cntr = ones_cntr + (K[index3]%2) %o A334955 index2 = end_index %o A334955 print(str(cntr1)+" "+str(ones_cntr)+"\n") %o A334955 cntr1 = cntr1 + 1 %Y A334955 Cf. A000002. %K A334955 nonn %O A334955 3,2 %A A334955 _Rakesh Khanna A_, May 24 2020