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-4 of 4 results.

A145799 a(n) = the largest integer that is an (odd) palindrome when represented in binary and that occurs in the binary representation of n.

Original entry on oeis.org

1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 5, 3, 5, 7, 15, 1, 17, 9, 9, 5, 21, 5, 7, 3, 9, 5, 27, 7, 7, 15, 31, 1, 33, 17, 17, 9, 9, 9, 9, 5, 9, 21, 21, 5, 45, 7, 15, 3, 17, 9, 51, 5, 21, 27, 27, 7, 9, 7, 27, 15, 15, 31, 63, 1, 65, 33, 33, 17, 17, 17, 17, 9, 73, 9, 9, 9, 9, 9, 15, 5, 17, 9, 9, 21, 85, 21, 21
Offset: 1

Views

Author

Leroy Quet, Oct 19 2008

Keywords

Comments

The binary expansion of a(n) is the largest (odd) palindrome that appears as a substring of the binary expansion of n. Nonzero binary palindromes are necessarily odd (see A006995).
For n = 2^k, a(n) = 1 is the largest binary palindrome in the binary representation of n.
a(2^k*A006995(n)) = A006995(n). - Ray Chandler, Oct 26 2008
a(m) = m iff m is a palindrome: a(A006995(n)) = A006995(n), a(A154809(n)) < A154809(n). - Reinhard Zumkeller, Sep 24 2015

Examples

			20 in binary is 10100. The largest binary palindrome included in this binary representation is 101, which is 5 in decimal. So a(20) = 5.
		

Crossrefs

Programs

  • Haskell
    a145799 = maximum . map (foldr (\b v -> 2 * v + b) 0) .
                        filter (\bs -> bs == reverse bs && head bs == 1) .
                        substr . bin where
       substr [] = []
       substr us'@(_:us) = sub us' ++ substr us where
          sub [] = []; sub (v:vs) = [v] : [v : ws | ws <- sub vs ]
       bin 0 = []; bin n = b : bin n' where (n', b) = divMod n 2
    -- Reinhard Zumkeller, Sep 24 2015
  • Mathematica
    Block[{nn = 87, s}, s = Reverse@ Select[IntegerDigits[#, 2] & /@ Range[2^Log2@ nn], PalindromeQ]; Table[With[{d = IntegerDigits[n, 2]}, FromDigits[#, 2] &@ SelectFirst[s, SequenceCount[d, #] > 0 &]], {n, nn}]] (* Michael De Vlieger, Sep 23 2017 *)

Extensions

Extended by Ray Chandler, Oct 26 2008

A056544 Smallest palindrome containing the digits of n as a subsequence.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 9, 101, 11, 121, 131, 141, 151, 161, 171, 181, 191, 202, 121, 22, 232, 242, 252, 262, 272, 282, 292, 303, 131, 232, 33, 343, 353, 363, 373, 383, 393, 404, 141, 242, 343, 44, 454, 464, 474, 484, 494, 505, 151, 252, 353, 454, 55, 565, 575
Offset: 1

Views

Author

Joseph L. Pe, Feb 10 2002

Keywords

Examples

			The smallest palindrome containing 21 as a subsequence is 121. So a(21) = 121.
		

Crossrefs

Cf. A002113, A082216, A145800 (binary variant).

Programs

  • Mathematica
    Do[k = 1; While[ StringPosition[ ToString[k], ToString[n]] == {} || ToString[k] != StringReverse[ ToString[k]], k++ ]; Print[k], {n, 1, 70} ]
  • PARI
    See Links section.

Formula

a(A002113(n)) = A002113(n). - Chai Wah Wu, Apr 13 2021

Extensions

Edited and extended by Robert G. Wilson v, Feb 12 2002

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

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
Showing 1-4 of 4 results.