OFFSET
1,3
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(m) = m iff m is a palindrome: a(A006995(n)) = A006995(n), a(A154809(n)) < A154809(n). - Reinhard Zumkeller, Sep 24 2015
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..16384
EXAMPLE
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.
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 *)
PROG
(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
CROSSREFS
KEYWORD
AUTHOR
Leroy Quet, Oct 19 2008
EXTENSIONS
Extended by Ray Chandler, Oct 26 2008
STATUS
approved