%I #21 Aug 13 2022 05:16:05
%S 3,13,313,13313,631331313313,10131331313313631331313313,
%T 1331363133131331310131331313313631331313313
%N a(1) = 3. For n > 1, a(n) = smallest prime not already seen forming a palindrome when a(n) and all previous terms are concatenated
%C From _Michael S. Branicky_, Aug 12 2022: (Start)
%C If terms are not constrained to be distinct, then 3, 3, 3, 3, ... and 3, 13, 13, 13, ... would be solutions.
%C a(12) has 1528 digits. (End)
%H Michael S. Branicky, <a href="/A113612/b113612.txt">Table of n, a(n) for n = 1..11</a>
%e 3, 313, 313313, 31331313313, ... are all palindromes.
%o (Python)
%o from sympy import isprime
%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[:i1][::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("0123456789"))
%o def agen():
%o s, seen = "3", {"3"}; yield from [3]
%o while True:
%o for t in folds(s):
%o if len(t) and t[0] != "0" and t not in seen and isprime(int(t)):
%o break
%o s += t; seen.add(t); yield int(t)
%o print(list(islice(agen(), 7))) # _Michael S. Branicky_, Aug 12 2022
%Y Cf. A113613.
%K nonn,base
%O 1,1
%A _Amarnath Murthy_, Nov 09 2005
%E Definition clarified by _Felix Fröhlich_, Oct 27 2014
%E Name clarified, a(2)a(4) corrected, and a(5) and beyond from _Michael S. Branicky_, Aug 12 2022
