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.
In other words, a(n) = n + [n/4] + [n/16] + ... where addition is performed in base 4 without carries. - David Radcliffe, Jun 22 2025
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(a, end=', ')
(Python)
def xor4(x, y): return 4*xor4(x//4, y//4) + (x+y)%4 if x else y
def a(n): return xor4(n, a(n//4)) if n else 0 # David Radcliffe, Jun 22 2025
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Alex Ratushnyak, Sep 26 2014
STATUS
approved
