OFFSET
0,4
COMMENTS
Swap the first 1 with the last 0 in the binary expansion of n.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..8190
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
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Sep 03 2014
EXTENSIONS
More terms from Alois P. Heinz, Sep 03 2014
STATUS
approved