login
If the run lengths in binary expansion of n are (r(1), ..., r(w)), then the run lengths in binary expansion of a(n) are (r(1), r(3), r(5), ..., r(6), r(4), r(2)).
3

%I #22 Dec 02 2019 21:15:57

%S 0,1,2,3,4,5,6,7,8,11,10,9,12,13,14,15,16,23,20,19,22,21,18,17,24,27,

%T 26,25,28,29,30,31,32,47,40,39,44,43,36,35,46,41,42,45,38,37,34,33,48,

%U 55,52,51,54,53,50,49,56,59,58,57,60,61,62,63,64,95,80,79

%N If the run lengths in binary expansion of n are (r(1), ..., r(w)), then the run lengths in binary expansion of a(n) are (r(1), r(3), r(5), ..., r(6), r(4), r(2)).

%C This sequence is a permutation of the nonnegative integers that preserves the binary length as well as the number of runs. See A330091 for the inverse.

%H Rémy Sigrist, <a href="/A329303/b329303.txt">Table of n, a(n) for n = 0..8192</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

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

%F If n has w binary runs, then a^A003558(w-1)(n) = n (where a^k denotes the k-th iterate of the sequence).

%e For n = 19999:

%e - the binary representation of 19999 is "100111000011111",

%e - the corresponding run lengths are (1, 2, 3, 4, 5),

%e - hence the run lengths of a(n) are (1, 3, 5, 4, 2),

%e - and its binary representation is "100011111000011",

%e - so a(n) = 18371.

%o (PARI) torl(n) = { my (rr=[]); while (n, my (r=valuation(n+(n%2),2)); rr = concat(r, rr); n\=2^r); rr }

%o shuffle(v) = { my (w=vector(#v), o=0, e=#v+1); for (k=1, #v, w[if (k%2, o++, e--)]=v[k]); w }

%o fromrl(rr) = { my (v=0); for (k=1, #rr, v = (v+(k%2))*2^rr[k]-(k%2)); v }

%o a(n) = fromrl(shuffle(torl(n)))

%Y See A330081 for a similar sequence.

%Y Cf. A003558, A194959, A330091 (inverse).

%K nonn,base

%O 0,3

%A _Rémy Sigrist_, Dec 01 2019