login
A043276
a(n) = maximal run length in base-2 representation of n.
34
1, 1, 2, 2, 1, 2, 3, 3, 2, 1, 2, 2, 2, 3, 4, 4, 3, 2, 2, 2, 1, 2, 3, 3, 2, 2, 2, 3, 3, 4, 5, 5, 4, 3, 3, 2, 2, 2, 3, 3, 2, 1, 2, 2, 2, 3, 4, 4, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 6, 6, 5, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 4, 4, 3, 2, 2, 2, 1, 2, 3, 3, 2, 2, 2, 3, 3, 4, 5, 5, 4, 3, 3, 2, 2, 2, 3, 3, 2
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
a(n) = max(A101211(n,k): k = 1..A005811(n)). - Reinhard Zumkeller, Dec 16 2013
LINKS
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
Cf. A043277-A043290 for base-3 to base-16 analogs.
Sequence in context: A355080 A165915 A269783 * A319416 A284559 A284583
KEYWORD
nonn,base,look
EXTENSIONS
More terms from Robert G. Wilson v, Dec 14 2008
STATUS
approved