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.

A341944 Next larger integer with same number of runs in binary expansion as n.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, Feb 24 2021

Keywords

Comments

Number of runs in binary expansion is given by A005811.
This is a permutation of A107907.

Examples

			The first terms in decimal and in binary, alongside A005811(n), are:
  n   a(n)  bin(n)  bin(a(n))  A005811(n)
  --  ----  ------  ---------  ----------
   1     3       1         11           1
   2     4      10        100           2
   3     7      11        111           1
   4     6     100        110           2
   5     9     101       1001           3
   6     8     110       1000           2
   7    15     111       1111           1
   8    12    1000       1100           2
   9    11    1001       1011           3
  10    18    1010      10010           4
  11    13    1011       1101           3
  12    14    1100       1110           2
		

Crossrefs

Programs

  • PARI
    a(n) = my (r=hammingweight(bitxor(n, n>>1))); for (k=n+1, oo, if (r==hammingweight(bitxor(k, k>>1)), return (k)))
    
  • Python
    def runs(n): return bin(n^(n>>1)).count('1')
    def a(n):
      nruns, m = runs(n), n + 1
      while runs(m) != nruns: m += 1
      return m
    print([a(n) for n in range(1, 67)]) # Michael S. Branicky, Feb 24 2021

Formula

A005811(a(n)) = A005811(n).
a(2^k-1) = 2^(k+1)-1 for any k > 0.