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.

A246594 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two adjacent bits in the binary expansion of n.

This page as a plain text file.
%I A246594 #33 Mar 22 2025 13:12:54
%S A246594 0,1,2,3,4,6,6,7,8,10,12,13,12,14,14,15,16,18,20,21,24,25,26,27,24,26,
%T A246594 28,29,28,30,30,31,32,34,36,37,40,41,42,43,48,49,50,51,52,53,54,55,48,
%U A246594 50,52,53,56,57,58,59,56,58,60,61,60,62,62,63,64,66,68
%N A246594 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two adjacent bits in the binary expansion of n.
%C A246594 In both this sequence and A246593 you are not allowed to touch any of the invisible 0's before the leading 1.
%C A246594 Scanning from the left, find first occurrence of '01' in binary expansion and replace with '10' and return decimal representation or return n if no such swap exists. - _Chai Wah Wu_, Sep 06 2014
%H A246594 Alois P. Heinz, <a href="/A246594/b246594.txt">Table of n, a(n) for n = 0..8192</a>
%e A246594 If n = 17 = 10001_2 then a(17) = 10010_2 = 18.
%t A246594 A246594[n_] := FromDigits[StringReplace[IntegerString[n, 2], "01" -> "10", 1], 2];
%t A246594 Array[A246594, 100, 0] (* _Paolo Xausa_, Mar 07 2025 *)
%o A246594 (Python)
%o A246594 def A246594(n):
%o A246594     s = bin(n)[2:]
%o A246594     for i in range(len(s)-1):
%o A246594         if s[i:i+2] == '01':
%o A246594             return int(s[:i]+'10'+s[i+2:], 2)
%o A246594     else:
%o A246594         return n # _Chai Wah Wu_, Sep 06 2014
%Y A246594 Cf. A241816, A246591, A246592, A246593.
%K A246594 nonn,base
%O A246594 0,3
%A A246594 _N. J. A. Sloane_, Sep 03 2014
%E A246594 Corrected definition and more terms from _Alois P. Heinz_, Sep 04 2014
%E A246594 Corrected typo in definition - _Chai Wah Wu_, Sep 06 2014