A309952 XOR contraction of binary representation of n.
0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 1, 1, 0, 4, 5, 5, 4, 6, 7, 7, 6, 6, 7, 7, 6, 4, 5, 5, 4, 4, 5, 5, 4, 6, 7, 7, 6, 6, 7, 7, 6, 4, 5, 5, 4, 0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 1, 1, 0, 8, 9, 9, 8, 10, 11, 11, 10, 10, 11, 11, 10, 8, 9, 9, 8, 12, 13, 13
Offset: 0
Examples
For n=19 we have the binary representation 10011 = 01 00 11. Calculating the xor of the pairs gives 1 0 0 which is 4 in binary and therefore a(19) = 4.
Links
Programs
-
Maple
a:= n-> `if`(n=0, 0, (r-> 2*a((n-r)/4) +r*(3-r)/2)(irem(n, 4))): seq(a(n), n=0..100); # Alois P. Heinz, Aug 26 2019
-
PARI
a(n) = {my(b = Vecrev(binary(n)), nb = #b\2, val = fromdigits(Vecrev(vector(nb, i, bitxor(b[2*i-1], b[2*i]))), 2)); if (#b % 2, val += 2^nb); val;} \\ Michel Marcus, Aug 26 2019
-
Python
def a(n): n = [int(k) for k in bin(n)[2:]] if len(n) % 2 != 0: n = [0] + n result = [] for i in range(0, len(n), 2): result.append(n[i] ^ n[i+1]) #xor return int("".join([str(k) for k in result]), 2)
-
Python
from itertools import zip_longest from operator import xor def A309952(n): return int(''.join(map(lambda x:str(xor(*x)),zip_longest((s:=tuple(int(d) for d in bin(n)[2:]))[::-2],s[-2::-2],fillvalue=0)))[::-1],2) # Chai Wah Wu, Jun 30 2022
Formula
a(0) = 0, a(4n) = 2*a(n), a(4n+1) = 2*a(n)+1, a(4n+2) = 2*a(n)+1, a(4n+3) = 2*a(n). - Florian Lang, Aug 26 2019
Comments