login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(n) = maximal run length in base-2 representation of n.
34

%I #31 Mar 10 2023 02:32:12

%S 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,

%T 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,

%U 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

%N a(n) = maximal run length in base-2 representation of n.

%C First occurrence of k is when n=2^k-1 and there is no last occurrence. - _Robert G. Wilson v_, Dec 14 2008

%C 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

%C a(n) = max(A101211(n,k): k = 1..A005811(n)). - _Reinhard Zumkeller_, Dec 16 2013

%H Reinhard Zumkeller, <a href="/A043276/b043276.txt">Table of n, a(n) for n = 1..10000</a>

%p A043276 := proc(n)

%p local a,rl,i ;

%p if n > 0 then

%p rl := 1 ;

%p else

%p rl := 0 ;

%p end if;

%p a := rl ;

%p dgs := convert(n,base,2) ;

%p for i from 2 to nops(dgs) do

%p if op(i,dgs) = op(i-1,dgs) then

%p rl := rl+1 ;

%p a := max(a,rl) ;

%p else

%p a := max(a,rl) ;

%p rl := 1;

%p end if;

%p end do:

%p a ;

%p end proc:

%p seq(A043276(n),n=1...80) ; # _R. J. Mathar_, Jun 04 2021

%t f[n_] := Max @@ Length /@ Split@IntegerDigits[n, 2]; Array[f, 105] (* _Robert G. Wilson v_, Dec 14 2008 *)

%o (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

%o (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

%o (Haskell)

%o a043276 = maximum . a101211_row -- _Reinhard Zumkeller_, Dec 16 2013

%o (Python)

%o from itertools import groupby

%o def A043276(n): return max(len(list(g)) for k, g in groupby(bin(n)[2:])) # _Chai Wah Wu_, Mar 09 2023

%Y Cf. A043277-A043290 for base-3 to base-16 analogs.

%K nonn,base,look

%O 1,3

%A _Clark Kimberling_

%E More terms from _Robert G. Wilson v_, Dec 14 2008