login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Sum of the partial sums of the run lengths of binary expansion of n, when starting scanning from the least significant end; Row sums of A227188 and A227738.
5

%I #50 Apr 09 2022 06:43:05

%S 1,3,2,5,6,4,3,7,8,10,9,6,7,5,4,9,10,12,11,14,15,13,12,8,9,11,10,7,8,

%T 6,5,11,12,14,13,16,17,15,14,18,19,21,20,17,18,16,15,10,11,13,12,15,

%U 16,14,13,9,10,12,11,8,9,7,6,13,14,16,15,18,19,17,16

%N Sum of the partial sums of the run lengths of binary expansion of n, when starting scanning from the least significant end; Row sums of A227188 and A227738.

%C Equivalently, sum of bit-indices in binary expansion of n (counted from the right hand end, with the least significant bit having bit-index 0) of the positions where a bit differs from its immediate right-hand neighbor, counted up to the first leading zero.

%C a(0) could be 0 or 1, depending on how the binary expansion of zero is conceived, thus its value is left unspecified here.

%C From _Jason Kimberley_, Feb 22 2022: (Start)

%C Also, the total length of string movement required to display the binary expansion of n by the positions of the vanes of vertical blinds (starting with all 0).

%C The transitions from 0000 to 1011 are:

%C 0001, 0011, 0111, 1111;

%C 1110, 1100, 1000;

%C The transitions from 0000 to 1101 are:

%C 0001, 0011, 0111, 1111;

%C 1110, 1100;

%C 1101. (End)

%H Antti Karttunen, <a href="/A227192/b227192.txt">Table of n, a(n) for n = 1..8192</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F a(n) = Sum_{i=0..A005811(n)-1} A227188(n,i). [Row sums of A227188]

%F Equivalently, for n>=1, a(n) = Sum_{i=(A173318(n-1)+1)..A173318(n)} A227738(i). [Row sums of A227738]

%F a(n) = A227183(n) + A000217(A005811(n)-1). [Alternative definition]

%F a(n) = A029931(A003188(n)).

%F Recurrence: a(2n) = a(n) + 2*A069010(n), a(2n+1) = a(2n) +1 or -1, according to if n is even or odd. - _Ralf Stephan_, Sep 04 2013

%e For 11, whose binary expansion is "1011", the run lengths, when starting scanning from the right, are: [2,1,1]. Their partial sums are [2,2+1,2+1+1] = [2,3,4] which sum to total 9, thus a(11)=9. Equivalently, the zero-based positions (counted from the right) where bits change from one to zero or vice versa in "...01011" are 2, 3, 4 and 2+3+4 = 9.

%e For 13, whose binary expansion is "1101", the run lengths similarly scanned are [1,1,2]. Their partial sums are [1,1+1,1+1+2] = [1,2,4] which sum to total 7, thus a(13)=7. Equivalently, the positions where bits change in "...01101" are 1, 2, 4 and 1+2+4 = 7.

%t Table[Tr[FoldList[Plus,0,Length /@ Split[Reverse[IntegerDigits[n,2]]]] ],{n,71}] - _Wouter Meeussen_, Aug 22 2013

%o (Scheme)

%o (define (A227192 n) (let loop ((i (- (A005811 n) 1)) (s 0)) (cond ((< i 0) s) (else (loop (- i 1) (+ s (A227188bi n i))))))) ;; This version sums the nonzero terms of the n-th row of table A227188.

%o (define (A227192v2 n) (+ (A227183 n) (A000217 (- (A005811 n) 1)))) ;; Another variant.

%o (define (A227192v3 n) (add A227738 (+ 1 (A173318 (- n 1))) (A173318 n))) ;; This sums terms of table A227738.

%o ;; With the help of this function that implements Sum_{i=lowlim..uplim} intfun(i)

%o (define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))

%o (Python)

%o def A227192(n):

%o '''Sum of the partial sums of the run lengths of binary expansion of n, starting from the least significant end.'''

%o s = 0

%o b = n%2

%o i = 0

%o while (n != 0):

%o n >>= 1

%o i += 1

%o if((n%2) != b):

%o b = n%2

%o s += i

%o return(s)

%o (PARI) a(n)=local(b,s,t);b=binary(n);s=#b;t=b[#b];forstep(i=#b-1,1,-1,if(b[i]!=t,s=s+#b-i;t=!t));s /* _Ralf Stephan_, Sep 04 2013 */

%o (Ruby)

%o def a(n)

%o k = n.to_s(2).scan(/((\d)\2*)/)

%o k.each_index.map { |i| (i + 1) * k[i][0].size }.reduce(:+)

%o end # _Peter Kagey_, Aug 06 2015

%Y Cf. A005811, A227183. Row sums of A227188 and A227738.

%K nonn,base,look

%O 1,2

%A _Antti Karttunen_, Jul 06 2013