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)
LINKS
FORMULA
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 (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
KEYWORD
AUTHOR
Antti Karttunen, Jul 06 2013
STATUS
approved