login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A247891
a(n) is Gray-coded in base 4 into n.
0
0, 1, 2, 3, 5, 6, 7, 4, 10, 11, 8, 9, 15, 12, 13, 14, 21, 22, 23, 20, 26, 27, 24, 25, 31, 28, 29, 30, 16, 17, 18, 19, 42, 43, 40, 41, 47, 44, 45, 46, 32, 33, 34, 35, 37, 38, 39, 36, 63, 60, 61, 62, 48, 49, 50, 51, 53, 54, 55, 52, 58, 59, 56, 57, 85, 86, 87, 84, 90
OFFSET
0,3
COMMENTS
Permutation of nonnegative numbers.
FORMULA
a(n) = n XOR4 [n/4] XOR4 [n/16] XOR4 [n/64] ... XOR4 [n/4^m] where m = [log(n)/log(4)], [x] is integer floor of x, and XOR4 is a base 4 analog of binary exclusive-OR operator.
PROG
(Python)
def basexor(a, b, base):
result = 0
digit = 1
while a or b:
da = a % base
db = b % base
a //= base
b //= base
sum = (da+db) % base
result += sum * digit
digit *= base
return result
base = 4 # 2 => A006068, 3 => A105529, 10 => A226134
for n in range(129):
a = n
b = n//base
while b:
a = basexor(a, b, base)
b //= base
print str(a)+', ',
CROSSREFS
Cf. A006068 (base 2), A105529 (base 3), A226134 (base 10).
Sequence in context: A339949 A160100 A371257 * A367407 A354370 A113821
KEYWORD
nonn,base
AUTHOR
Alex Ratushnyak, Sep 26 2014
STATUS
approved