cp's OEIS Frontend

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.

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.

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