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.

A344220 a(n) is the least k >= 0 such that n XOR k is a binary palindrome (where XOR denotes the bitwise XOR operator).

This page as a plain text file.
%I A344220 #20 Feb 19 2024 10:50:02
%S A344220 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,
%T A344220 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,
%U A344220 5,4,7,6,1,0,3,2,5,4,7,6,5,4,7,6,1,0,3
%N A344220 a(n) is the least k >= 0 such that n XOR k is a binary palindrome (where XOR denotes the bitwise XOR operator).
%C A344220 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.
%H A344220 Rémy Sigrist, <a href="/A344220/b344220.txt">Table of n, a(n) for n = 0..8191</a>
%H A344220 Rémy Sigrist, <a href="/A344220/a344220.png">Scatterplot of the ordinal transform of the first 2^18 terms</a>
%H A344220 Rémy Sigrist, <a href="/A344220/a344220_1.png">Scatterplot of (x, y) such that x XOR y is a binary palindrome and x, y < 1024</a>
%F A344220 a(n) = 0 iff n belongs to A006995.
%F A344220 A070939(n XOR a(n)) = A070939(n).
%F A344220 A344259(n XOR a(n)) = A344259(n).
%e A344220 For n=42:
%e A344220 - 42 XOR 0 = 42 ("101010" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 1 = 43 ("101011" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 2 = 40 ("101000" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 3 = 41 ("101001" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 4 = 46 ("101110" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 5 = 47 ("101111" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 6 = 44 ("101100" in binary) is not a binary palindrome,
%e A344220 - 42 XOR 7 = 45 ("101101" in binary) is a binary palindrome,
%e A344220 - so a(42) = 7.
%t A344220 A344220[n_] := Module[{k = -1}, While[!PalindromeQ[IntegerDigits[BitXor[n, ++k], 2]]];k]; Array[A344220, 100, 0] (* _Paolo Xausa_, Feb 19 2024 *)
%o A344220 (PARI) a(n) = my (b); for (k=0, oo, if ((b=binary(bitxor(n, k)))==Vecrev(b), return (k)))
%o A344220 (Python)
%o A344220 from itertools import count
%o A344220 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
%Y A344220 Cf. A006995, A070939, A295520, A330270, A344259.
%K A344220 nonn,base
%O A344220 0,11
%A A344220 _Rémy Sigrist_, May 12 2021