login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Change every other 1 bit in binary expansion of n to 0.
3

%I #15 Jul 15 2022 10:38:31

%S 0,1,2,2,4,4,4,5,8,8,8,9,8,9,10,10,16,16,16,17,16,17,18,18,16,17,18,

%T 18,20,20,20,21,32,32,32,33,32,33,34,34,32,33,34,34,36,36,36,37,32,33,

%U 34,34,36,36,36,37,40,40,40,41,40,41,42,42,64,64,64,65,64,65,66,66,64,65,66,66,68,68,68,69,64,65,66,66,68,68,68,69,72,72,72

%N Change every other 1 bit in binary expansion of n to 0.

%C a(n) obeys the recurrences a(2n) = a(n), a(4n+1) = 2a(n) + a(2n+1), a(8n+3) = 4a(n) + a(4n+3), and a(8n+7) = -2a(n) + a(2n+1) + 2a(4n+3).

%H Rémy Sigrist, <a href="/A265263/b265263.txt">Table of n, a(n) for n = 0..8192</a>

%e a(15) = 10, because if we delete the 2nd and 4th bits of 1111, we get 1010.

%o (PARI) a(n) = my (b=binary(n), o=0); for (k=1, #b, if (b[k], b[k]=o++%2)); fromdigits(b, 2) \\ _Rémy Sigrist_, Feb 19 2020

%o (Python)

%o def a(n):

%o switch, b, out = False, bin(n)[2:], ""

%o for bi in b:

%o if bi == "0": out += "0"

%o else: out += "0" if switch else "1"; switch = not switch

%o return int(out, 2)

%o print([a(n) for n in range(91)]) # _Michael S. Branicky_, Jul 15 2022

%K nonn,base

%O 0,3

%A _Jeffrey Shallit_, Dec 06 2015