login
A339413
a(0) = 0; for n > 0, a(n) = a(n-1) if c0 == c1; a(n) = a(n-1) - c0 if c0 > c1; a(n) = a(n - 1) + c1 if c1 > c0, where c0 and c1 are respectively the number of 0's and 1's in the binary expansion of n.
1
0, 1, 1, 3, 1, 3, 5, 8, 5, 5, 5, 8, 8, 11, 14, 18, 14, 11, 8, 11, 8, 11, 14, 18, 15, 18, 21, 25, 28, 32, 36, 41, 36, 32, 28, 28, 24, 24, 24, 28, 24, 24, 24, 28, 28, 32, 36, 41, 37, 37, 37, 41, 41, 45, 49, 54, 54, 58, 62, 67, 71, 76, 81, 87, 81, 76, 71, 67, 62
OFFSET
0,4
COMMENTS
The plot seems to have a fractal pattern.
The graph is similar to the Takagi (or blancmange) curve (which also involves bit counts). See A268289. - Kevin Ryde, Dec 04, 2020
LINKS
MATHEMATICA
Block[{a = {0}}, Do[AppendTo[a, a[[-1]] + Which[#1 > #2, #1, #1 < #2, -#2, True, 0] & @@ DigitCount[i, 2]], {i, 68}]; a] (* Michael De Vlieger, Dec 07 2020 *)
PROG
(Python)
from collections import Counter
a = [0]
for i in range(1, 10000):
counts = Counter(str(bin(i))[2:])
if counts['0'] > counts['1']:
a.append(a[-1] - counts['0'])
elif counts['1'] > counts['0']:
a.append(a[-1] + counts['1'])
else:
a.append(a[-1])
print(a)
(PARI) { for (n=0, 68, if (n==0, v=0, b=if (n, binary(n), [0]); c0=#b-c1=vecsum(b); if (c0>c1, v-=c0, c1>c0, v+=c1)); print1 (v", ")) } \\ Rémy Sigrist, Dec 25 2020
CROSSREFS
KEYWORD
easy,nonn,base
AUTHOR
Gioele Bertoncini, Dec 03 2020
STATUS
approved