login
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

%I #31 Apr 21 2026 00:18:49

%S 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,

%T 26,21,25,22,24,23,63,32,62,33,61,34,60,35,59,36,58,37,57,38,56,39,55,

%U 40,54,41,53,42,52,43,51,44,50,45,49,46,48,47,127,64,126

%N 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.

%C Permutation of the nonnegative integers.

%H Ruud H.G. van Tol, <a href="/A393980/b393980.txt">Table of n, a(n) for n = 0..10000</a>

%H Ruud H.G. van Tol, <a href="/A393980/a393980_1.svg">Picture of the first few spirals (svg-file)</a>

%H Ruud H.G. van Tol, <a href="/A393980/a393980_1.txt">Code for the svg-picture</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F a(2^k) = 2^(k+1) - 1.

%F a(2^k+1) = 2^k.

%e Sequence as a triangle:

%e 0;

%e 1;

%e 3, 2;

%e 7, 4, 6, 5;

%e 15, 8, 14, 9, 13, 10, 12, 11;

%e 31, 16, 30, 17, 29, 18, 28, 19, 27, 20, 26, 21, 25, 22, 24, 23;

%e 63, 32, 62, 33, ...

%o (PARI) a(n)= if(!n, 0, my(w=logint(n, 2)); if(n%2, n+2^w, 5*2^w-n-2)\2);

%K nonn,easy,look

%O 0,3

%A _Ruud H.G. van Tol_, Apr 03 2026