%I #31 Dec 25 2020 20:08:48
%S 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,
%T 28,32,36,41,36,32,28,28,24,24,24,28,24,24,24,28,28,32,36,41,37,37,37,
%U 41,41,45,49,54,54,58,62,67,71,76,81,87,81,76,71,67,62
%N 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.
%C The plot seems to have a fractal pattern.
%C The graph is similar to the Takagi (or blancmange) curve (which also involves bit counts). See A268289. - _Kevin Ryde_, Dec 04, 2020
%H Rémy Sigrist, <a href="/A339413/b339413.txt">Table of n, a(n) for n = 0..8192</a>
%t 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 *)
%o (Python)
%o from collections import Counter
%o a = [0]
%o for i in range(1, 10000):
%o counts = Counter(str(bin(i))[2:])
%o if counts['0'] > counts['1']:
%o a.append(a[-1] - counts['0'])
%o elif counts['1'] > counts['0']:
%o a.append(a[-1] + counts['1'])
%o else:
%o a.append(a[-1])
%o print(a)
%o (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
%Y Cf. A000120, A023416, A268289.
%K easy,nonn,base
%O 0,4
%A _Gioele Bertoncini_, Dec 03 2020
|