OFFSET
0,3
COMMENTS
Permutation of nonnegative numbers.
LINKS
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
for n in range(129):
a = n
b = n//base
while b:
a = basexor(a, b, base)
b //= base
print str(a)+', ',
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Alex Ratushnyak, Sep 26 2014
STATUS
approved