login
Run lengths in Golay-Rudin-Shapiro sequence A020985.
2

%I #17 Feb 12 2023 06:06:20

%S 3,1,2,1,4,3,1,1,3,1,2,1,1,3,3,1,4,1,2,1,4,3,1,4,1,2,1,1,3,3,1,1,3,1,

%T 2,1,4,3,1,1,3,1,2,1,1,3,3,1,1,3,1,2,1,4,3,1,4,1,2,1,1,3,3,1,4,1,2,1,

%U 4,3,1,1,3,1,2,1,1,3,3,1,4,1,2,1,4,3

%N Run lengths in Golay-Rudin-Shapiro sequence A020985.

%C a(2*n) = length of n-th run of 1s; a(2*n+1) = length of n-th run of -1s.

%H Reinhard Zumkeller, <a href="/A203531/b203531.txt">Table of n, a(n) for n = 0..10000</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/Rudin-ShapiroSequence.html">Rudin-Shapiro Sequence</a>

%o (Haskell)

%o import Data.List (group)

%o a203531 n = a203531_list !! n

%o a203531_list = map length $ group a020985_list

%o (Python)

%o from itertools import count, islice

%o def A203531_gen(): # generator of terms

%o c, a = 0, 1

%o for n in count(0):

%o if (n&(n>>1)).bit_count()&1^a:

%o c += 1

%o else:

%o yield c

%o c = 1

%o a ^= 1

%o A293531_list = list(islice(A203531_gen(),30)) # _Chai Wah Wu_, Feb 11 2023

%Y Cf. A020985.

%K nonn

%O 0,1

%A _Reinhard Zumkeller_, Jan 02 2012