OFFSET
0,3
COMMENTS
This sequence is a permutation of the nonnegative integers that preserves the binary length as well as the Hamming weight. See A330090 for the inverse.
LINKS
FORMULA
If n has w binary digits, then a^A003558(w-1)(n) = n (where a^k denotes the k-th iterate of the sequence).
EXAMPLE
For n = 1234:
- the binary expansion of 1234 is "10011010010",
- odd-indexed bits are "101100",
- even-indexed bits are "01001", and in reverse order "10010",
- hence the binary expansion of a(1234) is "10110010010",
- so a(1234) = 1426.
PROG
(PARI) shuffle(v) = { my (w=vector(#v), o=0, e=#v+1); for (k=1, #v, w[if (k%2, o++, e--)]=v[k]); w }
a(n) = fromdigits(shuffle(binary(n)), 2)
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Dec 01 2019
STATUS
approved