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.

Showing 1-1 of 1 results.

A161501 a(n) is the smallest positive integer that is a palindrome when represented in binary, and is made by appending some number (zero or more) of binary digits on the right of n's binary representation.

Original entry on oeis.org

1, 5, 3, 9, 5, 27, 7, 17, 9, 21, 45, 51, 27, 119, 15, 33, 17, 73, 153, 165, 21, 45, 93, 99, 51, 107, 27, 231, 119, 495, 31, 65, 33, 273, 561, 73, 297, 153, 313, 325, 165, 85, 693, 717, 45, 93, 189, 195, 99, 403, 51, 843, 107, 219, 443, 455, 231, 471, 119, 975, 495, 2015
Offset: 1

Views

Author

Leroy Quet, Jun 11 2009

Keywords

Examples

			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}.)
		

Crossrefs

Cf. A006995, A082216 (decimal variant), A145800, A161502.

Programs

  • 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

Extensions

More terms from Sean A. Irvine, Sep 27 2009
Showing 1-1 of 1 results.