OFFSET
0,11
COMMENTS
The binary expansions of n and of n XOR a(n) have the same length, say k, and their first ceiling(k/2) bits are the same.
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..8191
FORMULA
EXAMPLE
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.
MATHEMATICA
A344220[n_] := Module[{k = -1}, While[!PalindromeQ[IntegerDigits[BitXor[n, ++k], 2]]]; k]; Array[A344220, 100, 0] (* Paolo Xausa, Feb 19 2024 *)
PROG
(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
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, May 12 2021
STATUS
approved