login
A374176
a(n) is the maximum number of consecutive bit changes in the binary representation of n.
3
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, 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, 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
OFFSET
1,5
LINKS
FORMULA
a(n) = A038374(A038554(n)), with A038374(0) = 0. - Michael S. Branicky, Jul 06 2024
EXAMPLE
a(1117) = 3:
1117_2 = [1 0 0 0 1 0 1 1 1 0 1]
^ ^ ^ ^ ^ ^
1 3 2
consecutive changes
MAPLE
b:= n-> `if`(n<2, [0$2], (f-> (t-> [t, max(t, f[2])])(
`if`(n mod 4 in {0, 3}, 0, f[1]+1)))(b(iquo(n, 2)))):
a:= n-> b(n)[2]:
seq(a(n), n=1..105); # Alois P. Heinz, Jul 07 2024
PROG
(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}
(Python)
def a(n):
b, c, m = bin(n)[2:], 0, 0
for i in range(len(b)-1):
if b[i] != b[i+1]: c += 1
else: m = max(m, c); c = 0
return max(m, c)
print([a(n) for n in range(1, 89)]) # Michael S. Branicky, Jul 06 2024
(Python) # using formula
from itertools import groupby
def a(n): return max((len(list(g)) for k, g in groupby(bin(n^(n>>1))[3:]) if k=="1"), default=0)
print([a(n) for n in range(1, 89)]) # Michael S. Branicky, Jul 06 2024
CROSSREFS
Cf. A000975 (index of first occurrence of n).
Sequence in context: A221857 A133607 A103631 * A263191 A192517 A309896
KEYWORD
nonn,base
AUTHOR
Hugo Pfoertner, Jul 05 2024
STATUS
approved