login
Lexicographically earliest sequence of distinct terms such that the concatenation of three successive terms form a palindrome using the alphabet {1, 2}.
1

%I #21 Aug 10 2022 07:40:32

%S 1,2,21,22,12,122,121,221,22121,22122,12122,12122122,12122121,

%T 22122121,2212212122121,2212212122122,1212212122122,

%U 121221212212212122122,121221212212212122121,221221212212212122121,2212212122122121221212212212122121

%N Lexicographically earliest sequence of distinct terms such that the concatenation of three successive terms form a palindrome using the alphabet {1, 2}.

%C Also, lexicographically earliest sequence of distinct terms > 0 such that the concatenation of three successive terms form a palindrome in bases >= 3.

%C a(45) with 1597 digits is the first term > 10^1000.

%H Michael S. Branicky, <a href="/A355404/b355404.txt">Table of n, a(n) for n = 1..44</a>

%o (Python)

%o from itertools import count, islice, product

%o def pals(digs):

%o yield from digs

%o for d in count(2):

%o for p in product(digs, repeat=d//2):

%o left = "".join(p)

%o for mid in [[""], digs][d%2]:

%o yield left + mid + left[::-1]

%o def folds(s): # generator of suffixes of palindromes starting with s

%o for i in range((len(s)+1)//2, len(s)+1):

%o for mid in [True, False]:

%o t = s[:i] + (s[:i-1][::-1] if mid else s[:i][::-1])

%o if t.startswith(s):

%o yield t[len(s):]

%o yield from ("".join(p)+s[::-1] for p in pals("12"))

%o def agen():

%o s, t, seen = "1", "2", {"1", "2"}

%o yield from [1, 2]

%o while True:

%o for u in folds(s+t):

%o if len(u) > 0 and u not in seen: break

%o s, t = t, u

%o seen.add(u)

%o yield int(t)

%o print(list(islice(agen(), 21))) # updated _Michael S. Branicky_, Aug 09 2022

%Y Cf. A002113, A091789.

%K nonn,base

%O 1,2

%A _Michael S. Branicky_, Jul 01 2022