A069010 Number of runs of 1's in the binary representation of n.
0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 3, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3, 3, 2, 3, 2, 2, 1, 2, 2, 2, 2, 3, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3, 3, 2, 3, 2, 2, 2, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 3, 2, 3
Offset: 0
Examples
a(11) = 2 since 11 is 1011 in binary with two runs of 1's. a(12) = 1 since 12 is 1100 in binary with one run of 1's.
Links
- Tilman Piesk (terms 0..9999) & Antti Karttunen, Table of n, a(n) for n = 0..16384
- Louis Marin, Counting Polyominoes in a Rectangle b X h, arXiv:2406.16413 [cs.DM], 2024. See p. 148.
- Vladimir Shevelev, Two analogs of Thue-Morse sequence, arXiv:1603.04434 [math.NT], 2016.
- Ralf Stephan, Some divide-and-conquer sequences ...
- Ralf Stephan, Table of generating functions
Crossrefs
Programs
-
Maple
f:= proc(n) option remember; if n::even then procname(n/2) elif n mod 4 = 1 then 1 + procname((n-1)/2) else procname((n-1)/2) fi end proc: f(0):= 0: map(f, [$0..1000]); # Robert Israel, Sep 06 2015
-
Mathematica
Count[Split@ IntegerDigits[#, 2], n_ /; First@ n == 1] & /@ Range[0, 120] (* Michael De Vlieger, Sep 05 2015 *)
-
PARI
a(n) = (1 + (hammingweight(bitxor(n, n>>1)))) >> 1; \\ Gheorghe Coserea, Sep 05 2015
-
Python
def A069010(n): return sum(1 for d in bin(n)[2:].split('0') if len(d)) # Chai Wah Wu, Nov 04 2016
-
Scheme
(define (A069010 n) (/ (+ (A005811 n) (A000035 n)) 2)) ;; Antti Karttunen, Feb 05 2016
Formula
a(n) = ceiling(A005811(n)/2) = A005811(n) - A033264(n). If 2^k <= n < 3*2^(k-1) then a(n) = a(n-2^k)+1; if 3*2^(k-1) <= n < 2^(k+1) then a(n) = a(n-2^k).
a(2n) = a(n), a(2n+1) = a(n) + [n is even]. - Ralf Stephan, Aug 20 2003
G.f.: (1/(1-x)) * Sum_{k>=0} (t/(1+t))/(1+t^2), where t=x^2^k. - Ralf Stephan, Sep 07 2003
Comments