This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A344985 #19 Jul 07 2021 16:17:35 %S A344985 1,1,3,2,2,4,6,4,2,2,4,4,6,8,10,7,5,3,3,3,3,5,7,5,5,7,9,9,11,13,15,11, %T A344985 9,7,5,5,3,3,5,5,3,3,5,5,7,9,11,7,5,5,7,7,9,11,13,9,11,13,15,15,17,19, %U A344985 21,16,14,12,10,10,8,6,6,8,6,4,4,4,4,6,8,8 %N A344985 Sum of imbalance of all initial subsequences of the binary representation of n. %C A344985 The imbalance of a sequence of zeros and ones is given as the absolute value of the difference between the number of zeros and the number of ones (that is, the absolute value of A037861 if n is the sequence A007088). %H A344985 Alois P. Heinz, <a href="/A344985/b344985.txt">Table of n, a(n) for n = 1..16384</a> %F A344985 a(n) = a(floor(n/2)) + |A037861(n)|. - _R. J. Mathar_, Jul 07 2021 %e A344985 9 in binary is 1001. The imbalance of 1 is 1, the imbalance of 10 is 0, the imbalance of 100 is 1 and the imbalance of 1001 is 0. thus a(9)=1+0+1+0=2. %p A344985 imbal := proc(L) %p A344985 abs(numboccur(0, L) - numboccur(1, L)) %p A344985 end proc: %p A344985 A344985 := proc(n) %p A344985 dgs := ListTools[Reverse](convert(n,base,2)) ; %p A344985 add(imbal( dgs[1..l]),l=1..nops(dgs)) ; %p A344985 end proc: # _R. J. Mathar_, Jul 07 2021 %p A344985 # second Maple program: %p A344985 a:= proc(n) option remember; `if`(n=0, 0, a(iquo(n, 2))+ %p A344985 (l-> abs(add(1-2*i, i=l)))(Bits[Split](n))) %p A344985 end: %p A344985 seq(a(n), n=1..80); # _Alois P. Heinz_, Jul 07 2021 %o A344985 (PARI) a(n) = my(b=binary(n)); sum(k=1, #b, abs(sum(j=1, k, b[j]==1) - sum(j=1, k, b[j]==0))); \\ _Michel Marcus_, Jun 09 2021 %o A344985 (Python) %o A344985 def A344985(n): %o A344985 s, c, b = bin(n)[2:], 0, 0 %o A344985 for x in s: %o A344985 b += 1 if x == '1' else -1 %o A344985 c += abs(b) %o A344985 return c # _Chai Wah Wu_, Jul 07 2021 %Y A344985 Cf. A007088, A037861. %K A344985 nonn,base,look,easy %O A344985 1,3 %A A344985 _André Engels_, Jun 04 2021