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 A246593 #31 May 22 2025 10:21:40 %S A246593 0,1,2,3,4,6,6,7,8,12,12,14,12,14,14,15,16,24,24,26,24,28,28,30,24,28, %T A246593 28,30,28,30,30,31,32,48,48,50,48,52,52,54,48,56,56,58,56,60,60,62,48, %U A246593 56,56,58,56,60,60,62,56,60,60,62,60,62,62,63,64,96,96 %N A246593 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two bits in the binary expansion of n. %C A246593 In both this sequence and A246594 you are not allowed to touch any of the invisible 0's before the leading 1. %C A246593 Swap first 0 with last 1 in the binary expansion of n or return n if no such swap is possible. - _Chai Wah Wu_, Sep 08 2014 %H A246593 Alois P. Heinz, <a href="/A246593/b246593.txt">Table of n, a(n) for n = 0..8192</a> %e A246593 If n = 17 = 10001_2 then a(17) = 11000_2 = 24. %o A246593 (Python) %o A246593 from itertools import combinations %o A246593 def A246593(n): %o A246593 if n <= 1: %o A246593 return n %o A246593 else: %o A246593 s, y = bin(n)[2:], n %o A246593 for i in combinations(range(len(s)),2): %o A246593 s2 = int(s[:i[0]]+s[i[1]]+s[i[0]+1:i[1]]+s[i[0]]+s[i[1]+1:],2) %o A246593 if s2 > y: %o A246593 y = s2 %o A246593 return y %o A246593 # _Chai Wah Wu_, Sep 05 2014 %o A246593 (Python) %o A246593 # implement algorithm in comment %o A246593 def A246593(n): %o A246593 s = bin(n)[2:] %o A246593 s2 = s.rstrip('0') %o A246593 s3 = s2.lstrip('1') %o A246593 return(int(s2[:-len(s3)]+'1'+s3[1:-1]+'0'+s[len(s2):],2) if (len(s3) > 0 and n > 1) else n) %o A246593 # _Chai Wah Wu_, Sep 08 2014 %Y A246593 Cf. A241816, A246591, A246592, A246594. %K A246593 nonn,base %O A246593 0,3 %A A246593 _N. J. A. Sloane_, Sep 03 2014 %E A246593 Corrected definition and more terms from _Alois P. Heinz_, Sep 04 2014