cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A322463 Reverse runs of zeros in binary expansion of n and convert back to decimal.

This page as a plain text file.
%I A322463 #18 Dec 12 2018 15:40:05
%S A322463 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20,19,18,21,22,23,24,25,
%T A322463 26,27,28,29,30,31,32,33,40,35,36,41,44,39,34,37,42,43,38,45,46,47,48,
%U A322463 49,52,51,50,53,54,55,56,57,58,59,60,61,62,63,64,65,80,67
%N A322463 Reverse runs of zeros in binary expansion of n and convert back to decimal.
%C A322463 This sequence is a self-inverse permutation of nonnegative integers.
%H A322463 Rémy Sigrist, <a href="/A322463/b322463.txt">Table of n, a(n) for n = 0..8192</a>
%H A322463 Rémy Sigrist, <a href="/A322463/a322463.png">Colored scatterplot of (n, a(n)) for n = 0..2^18-1</a> (where the color is function of A005811(n))
%H A322463 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%H A322463 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A322463 A000120(a(n)) = A000120(n).
%F A322463 A005811(a(n)) = A005811(n).
%F A322463 a(A164710(n)) = A164710(n).
%F A322463 a(A322464(n)) = A322464(a(n)).
%F A322463 a(2^n) = 2^n.
%F A322463 a(2^n-1) = 2^n-1.
%e A322463 For n = 150:
%e A322463 - the binary representation of 150 is "10010110",
%e A322463 - we have three runs of zeros: "00", "0" and "0",
%e A322463 - we exchange the first and the third run, and the second remains in place,
%e A322463 - we obtain: "10101100",
%e A322463 - hence a(150) = 172.
%t A322463 a[n_] := Module[{s=Split[IntegerDigits[n,2]]}, m=Length[s]; m2=m-Mod[m,2]; If[m2>0, ind=Riffle[Range[1,m,2],Range[m2,1,-2]]; FromDigits[Flatten[s[[ind]]],2],n]]; Array[a, 100, 0] (* _Amiram Eldar_, Dec 12 2018 *)
%o A322463 (PARI) a(n) = {
%o A322463     my (r=n, z=[], v=0, p=1, i=0);
%o A322463     while (r, my (l=valuation(r+(r%2),2)); if (r%2==0, z=concat(l,z)); r\=2^l);
%o A322463     while (n, my (l=valuation(n+(n%2),2)); if (n%2, v+=(2^l-1)*p; p*=2^l, p*=2^z[i++]); n\=2^l);
%o A322463     return (v);
%o A322463 }
%Y A322463 See A322464 for the variant where we reverse the runs of ones.
%Y A322463 See A056539 for a similar sequence.
%Y A322463 Cf. A000120, A005811, A164710.
%K A322463 nonn,base,look
%O A322463 0,3
%A A322463 _Rémy Sigrist_, Dec 09 2018