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.

This page as a plain text file.
%I A341944 #9 Feb 27 2021 15:03:33
%S A341944 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,
%T A341944 34,29,30,33,32,63,48,35,36,39,38,41,40,47,44,43,74,45,46,53,50,49,56,
%U A341944 51,52,55,54,69,58,57,60,59,66,61,62,65,64,127,96,67,68
%N A341944 Next larger integer with same number of runs in binary expansion as n.
%C A341944 Number of runs in binary expansion is given by A005811.
%C A341944 This is a permutation of A107907.
%H A341944 Rémy Sigrist, <a href="/A341944/b341944.txt">Table of n, a(n) for n = 1..8191</a>
%H A341944 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A341944 A005811(a(n)) = A005811(n).
%F A341944 a(2^k-1) = 2^(k+1)-1 for any k > 0.
%e A341944 The first terms in decimal and in binary, alongside A005811(n), are:
%e A341944   n   a(n)  bin(n)  bin(a(n))  A005811(n)
%e A341944   --  ----  ------  ---------  ----------
%e A341944    1     3       1         11           1
%e A341944    2     4      10        100           2
%e A341944    3     7      11        111           1
%e A341944    4     6     100        110           2
%e A341944    5     9     101       1001           3
%e A341944    6     8     110       1000           2
%e A341944    7    15     111       1111           1
%e A341944    8    12    1000       1100           2
%e A341944    9    11    1001       1011           3
%e A341944   10    18    1010      10010           4
%e A341944   11    13    1011       1101           3
%e A341944   12    14    1100       1110           2
%o A341944 (PARI) a(n) = my (r=hammingweight(bitxor(n, n>>1))); for (k=n+1, oo, if (r==hammingweight(bitxor(k, k>>1)), return (k)))
%o A341944 (Python)
%o A341944 def runs(n): return bin(n^(n>>1)).count('1')
%o A341944 def a(n):
%o A341944   nruns, m = runs(n), n + 1
%o A341944   while runs(m) != nruns: m += 1
%o A341944   return m
%o A341944 print([a(n) for n in range(1, 67)]) # _Michael S. Branicky_, Feb 24 2021
%Y A341944 Cf. A000975, A005811, A057168, A107907.
%K A341944 nonn,base
%O A341944 1,1
%A A341944 _Rémy Sigrist_, Feb 24 2021