OFFSET
0,3
COMMENTS
Permutation of the nonnegative integers.
LINKS
Ruud H.G. van Tol, Table of n, a(n) for n = 0..10000
Ruud H.G. van Tol, Picture of the first few spirals (svg-file)
Ruud H.G. van Tol, Code for the svg-picture
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
KEYWORD
AUTHOR
Ruud H.G. van Tol, Apr 03 2026
STATUS
approved
