cp's OEIS Frontend

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.

A374176 a(n) is the maximum number of consecutive bit changes in the binary representation of n.

This page as a plain text file.
%I A374176 #23 Jul 07 2024 17:39:32
%S A374176 0,1,0,1,2,1,0,1,1,3,2,1,2,1,0,1,1,2,1,3,4,2,2,1,1,3,2,1,2,1,0,1,1,2,
%T A374176 1,2,3,1,1,3,3,5,4,2,2,2,2,1,1,2,1,3,4,2,2,1,1,3,2,1,2,1,0,1,1,2,1,2,
%U A374176 3,1,1,2,2,4,3,1,2,1,1,3,3,3,3,5,6,4,4,2,2,3,2,2,2,2,2,1,1,2,1,2,3,1,1,3,3
%N A374176 a(n) is the maximum number of consecutive bit changes in the binary representation of n.
%H A374176 Hugo Pfoertner, <a href="/A374176/b374176.txt">Table of n, a(n) for n = 1..8192</a>
%F A374176 a(n) = A038374(A038554(n)), with A038374(0) = 0. - _Michael S. Branicky_, Jul 06 2024
%e A374176 a(1117) = 3:
%e A374176   1117_2 = [1 0 0 0 1 0 1 1 1 0 1]
%e A374176              ^     ^ ^ ^     ^ ^
%e A374176              1       3        2
%e A374176             consecutive changes
%p A374176 b:= n-> `if`(n<2, [0$2], (f-> (t-> [t, max(t, f[2])])(
%p A374176         `if`(n mod 4 in {0, 3}, 0, f[1]+1)))(b(iquo(n, 2)))):
%p A374176 a:= n-> b(n)[2]:
%p A374176 seq(a(n), n=1..105);  # _Alois P. Heinz_, Jul 07 2024
%o A374176 (PARI) a(n) = {my(b=digits(n,2), d=#b, m=0, j=b[1], c=0); for(k=2, d, if(b[k]!=j, c++; m=max(m,c), c=0); j=b[k]); m}
%o A374176 (Python)
%o A374176 def a(n):
%o A374176     b, c, m = bin(n)[2:], 0, 0
%o A374176     for i in range(len(b)-1):
%o A374176         if b[i] != b[i+1]: c += 1
%o A374176         else: m = max(m, c); c = 0
%o A374176     return max(m, c)
%o A374176 print([a(n) for n in range(1, 89)]) # _Michael S. Branicky_, Jul 06 2024
%o A374176 (Python) # using formula
%o A374176 from itertools import groupby
%o A374176 def a(n): return max((len(list(g)) for k, g in groupby(bin(n^(n>>1))[3:]) if k=="1"), default=0)
%o A374176 print([a(n) for n in range(1, 89)]) # _Michael S. Branicky_, Jul 06 2024
%Y A374176 Cf. A005811, A037834, A038554, A038374.
%Y A374176 Cf. A000975 (index of first occurrence of n).
%K A374176 nonn,base
%O A374176 1,5
%A A374176 _Hugo Pfoertner_, Jul 05 2024