OFFSET
0,3
LINKS
FORMULA
EXAMPLE
43 in quaternary base (A007090) is written as '223' (2*16 + 2*4 + 3), which is then mapped to '332' = 3*16 + 3*4 + 2 = 62, thus a(43) = 62, and likewise a(62) = 43.
MAPLE
a:= proc(n) option remember; `if`(n=0, 0,
a(iquo(n, 4, 'r'))*4+[0, 1, 3, 2][r+1])
end:
seq(a(n), n=0..71); # Alois P. Heinz, Jan 25 2022
MATHEMATICA
Table[FromDigits[IntegerDigits[n, 4]/.{2->a, 3->b}/.{a->3, b->2}, 4], {n, 0, 75}] (* Harvey P. Dale, Nov 29 2011 *)
PROG
(Scheme) (define (A163241 n) (+ (A000695 (A003987bi (A059905 n) (A059906 n))) (* 2 (A000695 (A059906 n)))))
(Python)
def a000695(n):
n=bin(n)[2:]
x=len(n)
return sum([int(n[i])*4**(x - 1 - i) for i in range(x)])
def a059905(n): return sum([(n>>2*i&1)<<i for i in range(len(bin(n)[2:])//2 + 1)])
def a059906(n):
x=[int(k) for k in list(bin(n)[2:])][::-1]
return sum([x[2*i + 1]*2**i for i in range(len(x)//2)])
def a(n): return a000695(a059905(n)^a059906(n)) + 2*a000695(a059906(n))
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 26 2017
(PARI) f(d) = if (d==2, 4, if (x==d, 2, d));
a(n) = fromdigits(apply(f, digits(n, 4)), 4); \\ Michel Marcus, Jun 28 2017
(C) uint32_t a(uint32_t n) { return n ^ ((n >> 1) & 0x55555555); } // Falk Hüffner, Jan 22 2022
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Antti Karttunen, Jul 29 2009
EXTENSIONS
Edited by Charles R Greathouse IV, Nov 01 2009
STATUS
approved