OFFSET
1,16
COMMENTS
Overlaps count. For example, 64 in binary is 1000000, which means that a(64) = 4, not 2. - Harvey P. Dale, Jan 10 2016
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..65537
Eric Weisstein's World of Mathematics, Digit Block
FORMULA
a(1) = 0, and then after, a(2n) = a(n) + [n congruent to 0 mod 8], a(2n+1) = a(n). - Ralf Stephan, Aug 22 2003, corrected by Antti Karttunen, Oct 10 2017
MATHEMATICA
a[n_, bits_] := (idn = IntegerDigits[n, 2]; ln = Length[idn]; lb = Length[bits]; For[cnt = 0; k = 1, k <= ln - lb + 1, k++, If[idn[[k ;; k + lb - 1]] == bits, cnt++]]; cnt); Table[ a[n, {0, 0, 0}], {n, 1, 102} ] (* Jean-François Alcover, Oct 23 2012 *)
Table[SequenceCount[IntegerDigits[n, 2], {0, 0, 0}, Overlaps->True], {n, 110}] (* The program uses the SequenceCount function from Mathematica version 10 *) (* Harvey P. Dale, Jan 10 2016 *)
PROG
(PARI) a(n)=my(v=binary(n)); sum(i=3, #v, v[i]+v[i-1]+v[i-2]==0) \\ Charles R Greathouse IV, Dec 07 2011
(PARI)
a(n) = {
my(x = bitor(n, bitor(n>>1, n>>2)));
if (x == 0, 0, 1 + logint(x, 2) - hammingweight(x))
};
vector(102, i, a(i)) \\ Gheorghe Coserea, Sep 17 2015
(Scheme)
;; This uses Ralf Stephan's recurrence and memoization-macro definec:
(definec (A056974 n) (cond ((= 1 n) 0) ((even? n) (+ (if (zero? (modulo n 8)) 1 0) (A056974 (/ n 2)))) (else (A056974 (/ (- n 1) 2))))) ;; Antti Karttunen, Oct 10 2017
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
STATUS
approved