login
A162749
Write the n-th (odd) binary palindrome in binary. If there are an even number of digits, then combine the middle two digits into one digit. If there are an odd number of digits, then double the middle digit. a(n) is the decimal result.
2
3, 1, 9, 15, 5, 7, 33, 45, 51, 63, 17, 21, 27, 31, 129, 153, 165, 189, 195, 219, 231, 255, 65, 73, 85, 93, 99, 107, 119, 127, 513, 561, 585, 633, 645, 693, 717, 765, 771, 819, 843, 891, 903, 951, 975, 1023, 257, 273, 297, 313, 325, 341, 365, 381, 387, 403, 427
OFFSET
1,1
COMMENTS
a(n) is the A162750(n)th (odd) binary palindrome written in decimal. This sequence (A162749) is a permutation of the (odd) positive integers that are each palindromes when written in base 2.
EXAMPLE
The 8th binary palindrome is 21, which is 10101 in binary. Since there are an odd number of digits, double the middle digit to get 101101. a(8) is this written in decimal, which is 45.
51, the 13th palindrome when written in binary, is 110011 when written in base 2. Since this has an even number of digits, combine the middle two digits into one digit to get 11011. a(13) is the decimal equivalent of this, which is 27.
MATHEMATICA
bp[n_]:=Module[{len=Length[n]}, If[OddQ[len], FromDigits[Insert[n, n[[(len+1)/2]], (len+ 1)/2], 2], FromDigits[Delete[n, len/2], 2]]]; bp/@Select[Table[IntegerDigits[n, 2], {n, 1000}], PalindromeQ] (* Harvey P. Dale, Feb 06 2023 *)
PROG
(PARI) a(n) = my (p=A006995(n+1)); my (l=#binary(p), l2=2^ceil(l/2)); if (l%2==0, (p\(l2*2))*l2+(p%l2), (p\(l2\2))*l2+(p%l2)) \\ Rémy Sigrist, Nov 08 2018
CROSSREFS
Sequence in context: A318391 A157399 A288852 * A094796 A056843 A076806
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Jul 12 2009
EXTENSIONS
More terms from Rémy Sigrist, Nov 08 2018
STATUS
approved