A344220 a(n) is the least k >= 0 such that n XOR k is a binary palindrome (where XOR denotes the bitwise XOR operator).
0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2, 3, 2, 1, 0, 1, 0, 3, 2, 1, 0, 3, 2, 3, 2, 1, 0, 3, 2, 1, 0, 1, 0, 3, 2, 5, 4, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 3, 2, 1, 0, 7, 6, 5, 4, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 5, 4, 7, 6, 1, 0, 3
Offset: 0
Examples
For n=42: - 42 XOR 0 = 42 ("101010" in binary) is not a binary palindrome, - 42 XOR 1 = 43 ("101011" in binary) is not a binary palindrome, - 42 XOR 2 = 40 ("101000" in binary) is not a binary palindrome, - 42 XOR 3 = 41 ("101001" in binary) is not a binary palindrome, - 42 XOR 4 = 46 ("101110" in binary) is not a binary palindrome, - 42 XOR 5 = 47 ("101111" in binary) is not a binary palindrome, - 42 XOR 6 = 44 ("101100" in binary) is not a binary palindrome, - 42 XOR 7 = 45 ("101101" in binary) is a binary palindrome, - so a(42) = 7.
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..8191
- Rémy Sigrist, Scatterplot of the ordinal transform of the first 2^18 terms
- Rémy Sigrist, Scatterplot of (x, y) such that x XOR y is a binary palindrome and x, y < 1024
Programs
-
Mathematica
A344220[n_] := Module[{k = -1}, While[!PalindromeQ[IntegerDigits[BitXor[n, ++k], 2]]];k]; Array[A344220, 100, 0] (* Paolo Xausa, Feb 19 2024 *)
-
PARI
a(n) = my (b); for (k=0, oo, if ((b=binary(bitxor(n, k)))==Vecrev(b), return (k)))
-
Python
from itertools import count def A344220(n): return next(k for k in count(0) if (s := bin(n^k)[2:])[:(t:=len(s)+1>>1)]==s[:-t-1:-1]) # Chai Wah Wu, Aug 23 2023
Comments