login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
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. 6
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, 28, 30, 28, 30, 30, 31, 32, 48, 48, 50, 48, 52, 52, 54, 48, 56, 56, 58, 56, 60, 60, 62, 48, 56, 56, 58, 56, 60, 60, 62, 56, 60, 60, 62, 60, 62, 62, 63, 64, 96, 96 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
COMMENTS
In both this sequence and A246594 you are not allowed to touch any of the invisible 0's before the leading 1.
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
LINKS
EXAMPLE
If n = 17 = 10001_2 then a(17) = 11000_2 = 24.
PROG
(Python)
from itertools import combinations
def A246593(n):
....if n <= 1:
........return n
....else:
........s, y = bin(n)[2:], n
........for i in combinations(range(len(s)), 2):
............s2 = int(s[:i[0]]+s[i[1]]+s[i[0]+1:i[1]]+s[i[0]]+s[i[1]+1:], 2)
............if s2 > y:
................y = s2
........return y
# Chai Wah Wu, Sep 05 2014
(Python)
# implement algorithm in comment
def A246593(n):
....s = bin(n)[2:]
....s2 = s.rstrip('0')
....s3 = s2.lstrip('1')
....return(int(s2[:-len(s3)]+'1'+s3[1:-1]+'0'+s[len(s2):], 2) if (len(s3) > 0 and n > 1) else n)
# Chai Wah Wu, Sep 08 2014
CROSSREFS
Sequence in context: A334666 A163380 A233569 * A256999 A331857 A073138
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 03 2014
EXTENSIONS
Corrected definition and more terms from Alois P. Heinz, Sep 04 2014
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 18 16:22 EDT 2024. Contains 371780 sequences. (Running on oeis4.)