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.

A161502 a(n) is the smallest number of binary digits that when appended to the right side of the binary representation of n, forms a binary palindrome.

Original entry on oeis.org

0, 1, 0, 1, 0, 2, 0, 1, 0, 1, 2, 2, 1, 3, 0, 1, 0, 2, 3, 3, 0, 1, 2, 2, 1, 2, 0, 3, 2, 4, 0, 1, 0, 3, 4, 1, 3, 2, 3, 3, 2, 1, 4, 4, 0, 1, 2, 2, 1, 3, 0, 4, 1, 2, 3, 3, 2, 3, 1, 4, 3, 5, 0, 1, 0, 4, 5, 2, 4, 3, 4, 4, 0, 2, 5, 1, 4, 2, 3, 3, 2, 1, 5, 5, 0, 3, 4, 4, 3, 4, 2, 5, 0, 1, 2, 2, 1, 4, 0, 2, 4, 3, 4, 4, 3
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 on the right side of binary n to form a palindrome, then a(11) = 2. (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

Programs

  • Python
    def A161502(n):
        s = bin(n)[2:]
        if s == s[::-1]:
            return 0
        for i in range(1,len(s)):
            if s[i:] == s[-1:i-1:-1]:
                return i # Chai Wah Wu, Aug 27 2021

Extensions

More terms from Sean A. Irvine, Sep 27 2009