OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
LINKS
FORMULA
EXAMPLE
For n = 539:
- the base-4 expansion of 539 is "20123",
- the rightmost nonzero digit is 3, so we replace 1's by 2's and vice versa,
- so the base-4 expansion of a(539) is "10213", and a(539) = 295.
PROG
(PARI) a(n) = { my (m = if (n, [ [0, 1, 3, 2], [0, 3, 2, 1], [0, 2, 1, 3] ][(n / 4^valuation(n, 4)) % 4], [0, 1, 2, 3])); fromdigits(apply (d -> m[1+d], digits(n, 4)), 4); }
CROSSREFS
KEYWORD
AUTHOR
Rémy Sigrist, Apr 01 2023
STATUS
approved