login
Lexicographically earliest sequence of distinct nonnegative integers such that for any n >= 0, the concatenation of the binary expansions of n and a(n), in at least one way, is palindromic.
2

%I #12 Jul 28 2024 12:50:35

%S 0,1,5,3,9,2,11,7,17,4,21,6,19,22,23,15,33,8,41,12,37,10,13,14,35,38,

%T 43,27,39,46,47,31,65,16,81,24,73,20,25,28,69,18,85,26,77,45,29,30,67,

%U 70,83,51,75,86,91,59,71,78,87,55,79,94,95,63,129,32,161

%N Lexicographically earliest sequence of distinct nonnegative integers such that for any n >= 0, the concatenation of the binary expansions of n and a(n), in at least one way, is palindromic.

%C Leading zeros in binary expansions are ignored.

%C This sequence is a self-inverse permutation of the nonnegative integers.

%H Rémy Sigrist, <a href="/A374990/b374990.txt">Table of n, a(n) for n = 0..8191</a>

%H Rémy Sigrist, <a href="/A374990/a374990.gp.txt">PARI program</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%e The first terms, in decimal and in binary, alongside an appropriate palindrome, are:

%e n a(n) bin(n) bin(a(n)) palindromes

%e -- ---- ------ --------- -----------

%e 0 0 0 0 0

%e 1 1 1 1 11

%e 2 5 10 101 10101

%e 3 3 11 11 1111

%e 4 9 100 1001 1001001

%e 5 2 101 10 10101

%e 6 11 110 1011 1101011

%e 7 7 111 111 111111

%e 8 17 1000 10001 100010001

%e 9 4 1001 100 1001001

%e 10 21 1010 10101 101010101

%e 11 6 1011 110 1101011

%e 12 19 1100 10011 110010011

%o (PARI) \\ See Links section.

%o (Python)

%o from itertools import count, islice

%o def p(s): return s == s[::-1]

%o def c(v, w): return p(v+w) or p(w+v)

%o def agen(): # generator of terms

%o mink, a = 0, set()

%o for n in count(0):

%o bn = bin(n)[2:]

%o an = next(k for k in count(mink) if k not in a and c(bin(k)[2:], bn))

%o yield an

%o a.add(an)

%o while mink in a: mink += 1

%o print(list(islice(agen(), 70))) # _Michael S. Branicky_, Jul 28 2024

%Y Cf. A006995, A057889.

%K nonn,base

%O 0,3

%A _Rémy Sigrist_, Jul 26 2024