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.

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

Original entry on oeis.org

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

Views

Author

Keywords

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

Crossrefs

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

Programs

  • Haskell
    a043276 = maximum . a101211_row  -- Reinhard Zumkeller, Dec 16 2013
    
  • 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 *)
  • 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
    
  • 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

Extensions

More terms from Robert G. Wilson v, Dec 14 2008