A087117 Number of zeros in the longest string of consecutive zeros in the binary representation of n.
1, 0, 1, 0, 2, 1, 1, 0, 3, 2, 1, 1, 2, 1, 1, 0, 4, 3, 2, 2, 2, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 0, 5, 4, 3, 3, 2, 2, 2, 2, 3, 2, 1, 1, 2, 1, 1, 1, 4, 3, 2, 2, 2, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 0, 6, 5, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 4, 3, 2, 2, 2, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 1, 5, 4, 3, 3, 2, 2
Offset: 0
Links
Crossrefs
Positions of zeros are A000225.
Positions of terms <= 1 are A003754.
Positions of terms > 0 are A062289.
Positions of first appearances are A131577.
The version for prime indices is A252735.
The proper maximum is A333766.
The version for minimum is A333767.
Maximum prime index is A061395.
All of the following pertain to compositions in standard order (A066099):
- Length is A000120.
- Sum is A070939.
- Runs are counted by A124767.
- Strict compositions are A233564.
- Constant compositions are A272919.
- Runs-resistance is A333628.
- Weakly decreasing compositions are A114994.
- Weakly increasing compositions are A225620.
- Strictly decreasing compositions are A333255.
- Strictly increasing compositions are A333256.
Programs
-
Haskell
import Data.List (unfoldr, group) a087117 0 = 1 a087117 n | null $ zs n = 0 | otherwise = maximum $ map length $ zs n where zs = filter ((== 0) . head) . group . unfoldr (\x -> if x == 0 then Nothing else Just $ swap $ divMod x 2) -- Reinhard Zumkeller, May 01 2012
-
Maple
A087117 := proc(n) local d,l,zlen ; if n = 0 then return 1 ; end if; d := convert(n,base,2) ; for l from nops(d)-1 to 0 by -1 do zlen := [seq(0,i=1..l)] ; if verify(zlen,d,'sublist') then return l ; end if; end do: return 0 ; end proc; # R. J. Mathar, Nov 05 2012
-
Mathematica
nz[n_]:=Max[Length/@Select[Split[IntegerDigits[n,2]],MemberQ[#,0]&]]; Array[nz,110,0]/.-\[Infinity]->0 (* Harvey P. Dale, Sep 05 2017 *)
-
PARI
h(n)=if(n<2, return(0)); my(k=valuation(n,2)); if(k, max(h(n>>k), k), n++; n>>=valuation(n,2); h(n-1)) a(n)=if(n,h(n),1) \\ Charles R Greathouse IV, Apr 06 2022
Formula
a(2n+1) = a(n) (n>=1); indeed, the binary form of 2n+1 consists of the binary form of n with an additional 1 at the end - Emeric Deutsch, Aug 18 2017
For n > 0, a(n) = A333766(n) - 1. - Gus Wiseman, Apr 09 2020
Comments