login
A227192
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
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, 6, 5, 11, 12, 14, 13, 16, 17, 15, 14, 18, 19, 21, 20, 17, 18, 16, 15, 10, 11, 13, 12, 15, 16, 14, 13, 9, 10, 12, 11, 8, 9, 7, 6, 13, 14, 16, 15, 18, 19, 17, 16
OFFSET
1,2
COMMENTS
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.
a(0) could be 0 or 1, depending on how the binary expansion of zero is conceived, thus its value is left unspecified here.
From Jason Kimberley, Feb 22 2022: (Start)
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).
The transitions from 0000 to 1011 are:
0001, 0011, 0111, 1111;
1110, 1100, 1000;
The transitions from 0000 to 1101 are:
0001, 0011, 0111, 1111;
1110, 1100;
1101. (End)
FORMULA
a(n) = Sum_{i=0..A005811(n)-1} A227188(n,i). [Row sums of A227188]
Equivalently, for n>=1, a(n) = Sum_{i=(A173318(n-1)+1)..A173318(n)} A227738(i). [Row sums of A227738]
a(n) = A227183(n) + A000217(A005811(n)-1). [Alternative definition]
a(n) = A029931(A003188(n)).
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
EXAMPLE
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.
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.
MATHEMATICA
Table[Tr[FoldList[Plus, 0, Length /@ Split[Reverse[IntegerDigits[n, 2]]]] ], {n, 71}] - Wouter Meeussen, Aug 22 2013
PROG
(Scheme)
(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.
(define (A227192v2 n) (+ (A227183 n) (A000217 (- (A005811 n) 1)))) ;; Another variant.
(define (A227192v3 n) (add A227738 (+ 1 (A173318 (- n 1))) (A173318 n))) ;; This sums terms of table A227738.
;; With the help of this function that implements Sum_{i=lowlim..uplim} intfun(i)
(define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))
(Python)
def A227192(n):
'''Sum of the partial sums of the run lengths of binary expansion of n, starting from the least significant end.'''
s = 0
b = n%2
i = 0
while (n != 0):
n >>= 1
i += 1
if((n%2) != b):
b = n%2
s += i
return(s)
(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 */
(Ruby)
def a(n)
k = n.to_s(2).scan(/((\d)\2*)/)
k.each_index.map { |i| (i + 1) * k[i][0].size }.reduce(:+)
end # Peter Kagey, Aug 06 2015
CROSSREFS
Cf. A005811, A227183. Row sums of A227188 and A227738.
Sequence in context: A198755 A134237 A341521 * A360260 A099889 A115511
KEYWORD
nonn,base,look
AUTHOR
Antti Karttunen, Jul 06 2013
STATUS
approved