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!)
A246591 Smallest number that can be obtained by swapping 2 bits in the binary expansion of n. 5
0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 3, 7, 5, 7, 7, 15, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11, 15, 13, 15, 15, 31, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11, 15, 13, 15, 15, 31, 17, 19, 19, 23, 21, 23, 23, 31, 25, 27, 27, 31, 29, 31, 31, 63, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,4
COMMENTS
Swap the first 1 with the last 0 in the binary expansion of n.
LINKS
EXAMPLE
If n = 12 = 1100_2 then a(12) = 0101_2 = 5.
PROG
(Python)
from itertools import combinations
def A246591(n):
....if n <= 1:
........return n
....else:
........s = bin(n)[2:]
........l = len(s)
........y = 2**l-1
........for i in combinations(range(l), 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)
def A246591(n):
....s = bin(n)[2:]
....s2 = s.rstrip('1')
....return(int(s2[1:-1]+'1'+s[len(s2):], 2) if (len(s2) > 0 and n > 1) else n)
# Chai Wah Wu, Sep 08 2014
CROSSREFS
Sequence in context: A205145 A061892 A038573 * A173465 A151837 A356354
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 03 2014
EXTENSIONS
More terms from Alois P. Heinz, Sep 03 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 19 21:09 EDT 2024. Contains 371798 sequences. (Running on oeis4.)