login
A393980
On the nonnegative integer number line, go to the first next unused power of 2 minus 1, then spiral back to pick up any skipped numbers, and repeat.
1
0, 1, 3, 2, 7, 4, 6, 5, 15, 8, 14, 9, 13, 10, 12, 11, 31, 16, 30, 17, 29, 18, 28, 19, 27, 20, 26, 21, 25, 22, 24, 23, 63, 32, 62, 33, 61, 34, 60, 35, 59, 36, 58, 37, 57, 38, 56, 39, 55, 40, 54, 41, 53, 42, 52, 43, 51, 44, 50, 45, 49, 46, 48, 47, 127, 64, 126
OFFSET
0,3
COMMENTS
Permutation of the nonnegative integers.
FORMULA
a(2^k) = 2^(k+1) - 1.
a(2^k+1) = 2^k.
EXAMPLE
Sequence as a triangle:
0;
1;
3, 2;
7, 4, 6, 5;
15, 8, 14, 9, 13, 10, 12, 11;
31, 16, 30, 17, 29, 18, 28, 19, 27, 20, 26, 21, 25, 22, 24, 23;
63, 32, 62, 33, ...
PROG
(PARI) a(n)= if(!n, 0, my(w=logint(n, 2)); if(n%2, n+2^w, 5*2^w-n-2)\2);
CROSSREFS
Sequence in context: A316385 A341911 A341916 * A360960 A371974 A344878
KEYWORD
nonn,easy,look
AUTHOR
Ruud H.G. van Tol, Apr 03 2026
STATUS
approved