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.

Showing 1-1 of 1 results.

A322464 Reverse runs of ones in binary expansion of n and convert back to decimal.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 12, 11, 14, 15, 16, 17, 18, 25, 20, 21, 26, 29, 24, 19, 22, 27, 28, 23, 30, 31, 32, 33, 34, 49, 36, 37, 50, 57, 40, 41, 42, 53, 52, 45, 58, 61, 48, 35, 38, 51, 44, 43, 54, 59, 56, 39, 46, 55, 60, 47, 62, 63, 64, 65, 66, 97
Offset: 0

Views

Author

Rémy Sigrist, Dec 09 2018

Keywords

Comments

This sequence is a self-inverse permutation of nonnegative integers.

Examples

			For n = 150:
- the binary representation of 150 is "10010110",
- we have three runs of ones: "1", "1" and "11",
- we exchange the first and the third run, and the second remains in place,
- we obtain: "11001010",
- hence a(150) = 202.
		

Crossrefs

See A322463 for the variant where we reverse the runs of zeros.

Programs

  • Mathematica
    a[n_] := Module[{s=Split[IntegerDigits[n,2]]}, m=Length[s]; If[m>1, m2 = m-1 + Mod[m,2]; ind=Riffle[Range[m2,1,-2],Range[2,m,2]]; FromDigits[Flatten[ s[[ind]]],2], n]]; Array[a,120,0] (* Amiram Eldar, Dec 12 2018 *)
  • PARI
    a(n) = {
        my (r=n, o=[], v=0, p=1, i=0);
        while (r, my (l=valuation(r+(r%2),2)); if (r%2, o=concat(l,o)); r\=2^l);
        while (n, my (l=valuation(n+(n%2),2)); if (n%2, v+=(2^o[i++]-1)*p; p*=2^o[i], p*=2^l); n\=2^l);
        return (v);
    }

Formula

A000120(a(n)) = A000120(n).
A005811(a(n)) = A005811(n).
a(A322463(n)) = A322463(a(n)).
a(2^n) = 2^n.
a(2^n-1) = 2^n-1.
Showing 1-1 of 1 results.