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.
%I A073137 #43 Jan 30 2025 16:24:35 %S A073137 0,1,2,3,4,5,5,7,8,9,9,11,9,11,11,15,16,17,17,19,17,19,19,23,17,19,19, %T A073137 23,19,23,23,31,32,33,33,35,33,35,35,39,33,35,35,39,35,39,39,47,33,35, %U A073137 35,39,35,39,39,47,35,39,39,47,39,47,47,63,64,65,65,67,65,67,67,71,65 %N A073137 a(n) is the least number whose binary representation has the same number of 0's and 1's as n. %C A073137 A023416(a(n)) = A023416(n), A000120(a(n)) = A000120(n). %C A073137 Fixed points are { 0 } union { A099627 }. - _Alois P. Heinz_, Jan 30 2025 %H A073137 Reinhard Zumkeller, <a href="/A073137/b073137.txt">Table of n, a(n) for n = 0..10000</a> %H A073137 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a> %F A073137 a(0)=0, a(1)=1; for n > 1, let C = 2^(floor(log_2(n))-1) = A072376(n); then a(n) = a(n-C) + C if n < 3*C; otherwise a(n) = 2*a(n - 2*C) + 1. [corrected by _Jon E. Schoenfield_, Jun 27 2021] %F A073137 For n > 0: a(n) = (2^(A000120(n) - 1)) * (2^A023416(n) + 1) - 1. - Corrected by _Michel Marcus_, Nov 15 2013 %e A073137 a(20)=17, as 20='10100' and 17 is the smallest number having two 1's and three 0's: 17='10001', 18='10010', 20='10100' and 24='11000'. %p A073137 a:= n-> (l-> (2^nops(l)+2^add(i, i=l))/2-1)(Bits[Split](n)): %p A073137 seq(a(n), n=0..100); # _Alois P. Heinz_, Jun 26 2021 %t A073137 lnb[n_]:=Module[{sidn=Sort[IntegerDigits[n,2]]},FromDigits[Join[{1}, Most[ sidn]],2]]; Join[{0},Array[lnb,80]] (* _Harvey P. Dale_, Aug 04 2014 *) %o A073137 (Python) %o A073137 def a(n): %o A073137 b = bin(n)[2:]; z = b.count('0'); w = len(b) - z %o A073137 return int('1'*(w > 0) + '0'*z + '1'*(w-1), 2) %o A073137 print([a(n) for n in range(73)]) # _Michael S. Branicky_, Jun 26 2021 %o A073137 (Python) %o A073137 def a(n): b = bin(n)[2:]; return int(b[0] + "".join(sorted(b[1:])), 2) %o A073137 print([a(n) for n in range(73)]) # _Michael S. Branicky_, Jun 26 2021 %o A073137 (PARI) a(n) = if(n==0,0, 1<<logint(n,2) + 1<<(hammingweight(n)-1) - 1); \\ _Kevin Ryde_, Jun 26 2021 %Y A073137 Cf. A007088, A073138, A000523, A073139, A073140, A073141, A072376, A099627. %K A073137 nonn %O A073137 0,3 %A A073137 _Reinhard Zumkeller_, Jul 16 2002