A056979 Number of blocks of {1, 0, 1} in binary expansion of n.
0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 2, 2, 1, 2, 1, 1, 0, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 2, 3, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 0, 0, 0, 0, 0, 1, 0
Offset: 1
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
- J.-P. Allouche, J. Shallit, The Ring of k-regular Sequences II
- Eric Weisstein's World of Mathematics, Digit Block
- Index entries for sequences related to binary expansion of n
Programs
-
Haskell
import Data.List (tails, isPrefixOf) a056979 = sum . map (fromEnum . ([1,0,1] `isPrefixOf`)) . tails . a030308_row -- Reinhard Zumkeller, Jun 17 2012
-
Mathematica
a[1] = a[2] = 0; a[n_] := a[n] = If[EvenQ[n], a[n/2], a[(n - 1)/2] + Boole[Mod[(n - 1)/2, 4] == 2]]; Table[a[n], {n, 1, 102}] (* Jean-François Alcover, Oct 22 2012, after Ralf Stephan *)
-
PARI
a(n) = hammingweight(bitnegimply(bitand(n, n>>2), n>>1)); vector(102, i, a(i)) \\ Gheorghe Coserea, Sep 17 2015
Formula
a(2n) = a(n), a(2n+1) = a(n) + [n congruent to 2 mod 4]. - Ralf Stephan, Aug 22 2003
Comments