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 A246592 #20 Mar 22 2025 12:55:44 %S A246592 0,1,1,3,2,3,5,7,4,5,6,7,10,11,13,15,8,9,10,11,12,13,14,15,20,21,22, %T A246592 23,26,27,29,31,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,40,41, %U A246592 42,43,44,45,46,47,52,53,54,55,58,59,61,63,32,33,34,35,36 %N A246592 Smallest number that can be obtained by swapping 2 adjacent bits in the binary expansion of n. %C A246592 Scanning from the left, find first occurrence of '10' in binary expansion and replace with '01' and return decimal representation or return n if no such swap exists. - _Chai Wah Wu_, Sep 06 2014 %H A246592 Alois P. Heinz, <a href="/A246592/b246592.txt">Table of n, a(n) for n = 0..10000</a> %e A246592 If n = 9 = 1001_2 then a(9) = 0101_2 = 5. %t A246592 A246592[n_] := FromDigits[StringReplace[IntegerString[n, 2], "10" -> "01", 1], 2]; %t A246592 Array[A246592, 100, 0] (* _Paolo Xausa_, Mar 07 2025 *) %o A246592 (Python) %o A246592 def A246592(n): %o A246592 s = bin(n)[2:] %o A246592 for i in range(len(s)-1): %o A246592 if s[i:i+2] == '10': %o A246592 return int(s[:i]+'01'+s[i+2:], 2) %o A246592 else: %o A246592 return n # _Chai Wah Wu_, Sep 06 2014 %Y A246592 Cf. A241816, A246591, A246593, A246594. %K A246592 nonn,base %O A246592 0,4 %A A246592 _N. J. A. Sloane_, Sep 03 2014 %E A246592 More terms from _Alois P. Heinz_, Sep 03 2014