OFFSET
1,2
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..8192
EXAMPLE
11 (decimal) in binary is 1011. Appending 01 to the right side of 1011 forms the binary palindrome 101101, which is 45 in decimal. Since two binary digits is the smallest number of digits that need to be appended to form a palindrome, then a(11) = 45. (Note that 45 is not the smallest positive number that when represented in binary is a palindrome and contains 1011 as a substring. That would instead be 11011 {binary} = 27 {decimal}.)
PROG
(PARI) a(n, base=2) = { my (b=digits(n, base)); if (b==Vecrev(b), return (n), my (t=[]); for (k=1, #b, t=concat(b[k], t); my (bt=concat(b, t)); if (bt==Vecrev(bt), return (fromdigits(bt, base))))) } \\ Rémy Sigrist, Mar 22 2020
(Python)
def A161501(n):
s = bin(n)[2:]
if s == s[::-1]:
return n
for i in range(1, len(s)):
if s[i:] == s[-1:i-1:-1]:
return int(s+s[i-1::-1], 2) # Chai Wah Wu, Aug 27 2021
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Jun 11 2009
EXTENSIONS
More terms from Sean A. Irvine, Sep 27 2009
STATUS
approved