OFFSET
1,3
COMMENTS
First occurrence of k is when n=2^k-1 and there is no last occurrence. - Robert G. Wilson v, Dec 14 2008
Sequences A000975, A037969, A037970, A037971 list numbers for which a(n)=1, a(n)=2, a(n)=3, a(n)=4. - M. F. Hasler, Jul 23 2013
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
MAPLE
A043276 := proc(n)
local a, rl, i ;
if n > 0 then
rl := 1 ;
else
rl := 0 ;
end if;
a := rl ;
dgs := convert(n, base, 2) ;
for i from 2 to nops(dgs) do
if op(i, dgs) = op(i-1, dgs) then
rl := rl+1 ;
a := max(a, rl) ;
else
a := max(a, rl) ;
rl := 1;
end if;
end do:
a ;
end proc:
seq(A043276(n), n=1...80) ; # R. J. Mathar, Jun 04 2021
MATHEMATICA
f[n_] := Max @@ Length /@ Split@IntegerDigits[n, 2]; Array[f, 105] (* Robert G. Wilson v, Dec 14 2008 *)
PROG
(PARI) A043276(n, b=2)={my(m, c=1); while(n>0, n%b==(n\=b)%b && c++ && next; m=max(m, c); c=1); m} \\ M. F. Hasler, Jul 23 2013
(PARI) a(n)=my(r, t); while(n, t=valuation(n, 2); if(t>r, r=t); n>>=t; t=valuation(n+1, 2); if(t>r, r=t); n>>=t); r \\ Charles R Greathouse IV, Nov 02 2016
(Haskell)
a043276 = maximum . a101211_row -- Reinhard Zumkeller, Dec 16 2013
(Python)
from itertools import groupby
def A043276(n): return max(len(list(g)) for k, g in groupby(bin(n)[2:])) # Chai Wah Wu, Mar 09 2023
CROSSREFS
KEYWORD
AUTHOR
EXTENSIONS
More terms from Robert G. Wilson v, Dec 14 2008
STATUS
approved