login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A038374 Length of longest contiguous block of 1's in binary expansion of n. 25
1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 2, 2, 2, 2, 3, 3, 4, 5, 1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 2, 3, 4, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 6, 1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 2, 2, 2 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,3
LINKS
FORMULA
a(n) >= A089309(n). a(n) >= A089310(n). a(2^i)=1. a(2^i-1)=i. - R. J. Mathar, Jun 15 2006
May be defined by the recurrence given in A245196, taking G(n)=n+1 (n>=0) and m=1. - N. J. A. Sloane, Jul 25 2014
EXAMPLE
a(157) = 3 because 157 in base 2 is 10011101 and longest contiguous block of 1's is of length 3.
May be arranged into blocks of lengths 1, 2, 4, 8, 16, ...:
1,
1, 2,
1, 1, 2, 3,
1, 1, 1, 2, 2, 2, 3, 4,
1, 1, 1, 2, 1, 1, 2, 3, 2, 2, 2, 2, 3, 3, 4, 5,
1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 2, 3, 4, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 6,
... - N. J. A. Sloane, Jul 25 2014
MAPLE
A038374 := proc(n) local nshft, thisr, resul; nshft := n ; resul :=0 ; thisr :=0 ; while nshft > 0 do if nshft mod 2 <> 0 then thisr := thisr+1 ; else resul := max(resul, thisr) ; thisr := 0 ; fi ; nshft := floor(nshft/2) ; od ; resul := max(resul, thisr) ; RETURN(resul) ; end : for n from 1 to 80 do printf("%d, ", A038374(n)) ; od : # R. J. Mathar, Jun 15 2006
MATHEMATICA
Table[Max[Length/@DeleteCases[Split[IntegerDigits[n, 2]], _?(MemberQ[ #, 0] &)]], {n, 120}] (* Harvey P. Dale, Jun 10 2013 *)
PROG
(Haskell)
import Data.List (unfoldr, group)
a038374 = maximum . map length . filter ((== 1) . head) . group .
unfoldr (\x -> if x == 0 then Nothing else Just $ swap $ divMod x 2)
-- Reinhard Zumkeller, May 01 2012
(PARI) a(n)=if (n==0, return (0)); n>>=valuation(n, 2); if(n<2, return(n)); my(e=valuation(n+1, 2)); max(e, a(n>>e)) \\ Charles R Greathouse IV, Jan 12 2014; edited by Michel Marcus, Apr 14 2019
(Python)
from itertools import groupby
def a(n): return max(len(list(g)) for k, g in groupby(bin(n)[1:]) if k=='1')
print([a(n) for n in range(1, 91)]) # Michael S. Branicky, Jul 04 2022
CROSSREFS
Sequence in context: A265754 A089309 A126387 * A284569 A272604 A284580
KEYWORD
base,easy,nonn,tabf
AUTHOR
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified March 19 06:17 EDT 2024. Contains 370952 sequences. (Running on oeis4.)