login
a(n) is the greatest number m not yet in the sequence such that the binary expansions of m and of n have the same run lengths (up to order but with multiplicity).
4

%I #32 Aug 23 2020 20:51:38

%S 0,1,2,3,6,5,4,7,14,13,10,11,12,9,8,15,30,29,26,27,22,21,20,23,28,25,

%T 18,19,24,17,16,31,62,61,58,59,54,53,52,57,46,45,42,43,50,41,40,47,60,

%U 55,44,51,38,37,36,49,56,39,34,35,48,33,32,63,126,125,122

%N a(n) is the greatest number m not yet in the sequence such that the binary expansions of m and of n have the same run lengths (up to order but with multiplicity).

%C This sequence has similarities with A331274; here we consider run lengths in binary expansions, there binary digits.

%C This sequence is a self-inverse permutation of the nonnegative numbers.

%C This sequence preserves the number of binary digits (A070939) and the number of runs in binary expansions (A005811).

%C This sequence has interesting graphical features (see Links section).

%H Rémy Sigrist, <a href="/A337242/b337242.txt">Table of n, a(n) for n = 0..8191</a>

%H Rémy Sigrist, <a href="/A337242/a337242.png">Scatterplot of the first 2^20 terms</a>

%H Rémy Sigrist, <a href="/A337242/a337242_1.png">Scatterplot of (n-2^19, a(n)-2^19) for n = 2^19..2^20-1</a>

%H Rémy Sigrist, <a href="/A337242/a337242.gp.txt">PARI program for A337242</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 a(2^k-1) = 2^k-1 for any k >= 0.

%e For n = 7280:

%e - 7280 has binary expansion "1110001110000",

%e - the corresponding run lengths are: {3, 3, 3, 4},

%e - there are four numbers k with the same multiset of run lengths:

%e k bin(k) run lengths

%e ---- --------------- -----------

%e 7224 "1110000111000" {3, 4, 3, 3}

%e 7280 "1110001110000" {3, 3, 3, 4}

%e 7288 "1110001111000" {3, 3, 4, 3}

%e 7736 "1111000111000" {4, 3, 3, 3}

%e - so a(7224) = 7736,

%e a(7280) = 7288,

%e a(7288) = 7280,

%e a(7736) = 7224.

%t Nest[Function[{a, m}, Append[a, SelectFirst[m, FreeQ[a, #] &]]] @@ {#1, Sort[Map[FromDigits[Join @@ MapIndexed[ConstantArray[Boole[OddQ@ First[#2]], #1] &, #], 2] &, Permutations[Length /@ Split@ IntegerDigits[#2, 2]]], Greater]} & @@ {#, Length@ #} &, {0}, 66] (* _Michael De Vlieger_, Aug 22 2020 *)

%o (PARI) See Links section.

%Y Cf. A005811, A070939, A101211, A331274, A335834, A335835.

%K nonn,look,base

%O 0,3

%A _Rémy Sigrist_, Aug 21 2020