%I #30 Mar 19 2023 13:35:18
%S 1,2,3,4,7,6,5,8,9,22,141,88,111,202,55,222,11,212,99,232,121,252,101,
%T 66,131,242,191,272,77,282,151,292,171,262,181,606,313,414,343,444,
%U 353,44,303,424,33,434,323,404,383,474,535,484,373,454,333,464,363
%N Lexicographically earliest sequence of distinct positive base-10 palindromes such that a(n) + a(n+1) is prime.
%H Michael De Vlieger, <a href="/A361444/b361444.txt">Table of n, a(n) for n = 1..10000</a>
%H Michael De Vlieger, <a href="/A361444/a361444.png">Log log scatterplot of a(n)</a>, n = 1..10^4, with a color function showing number of decimal digits of a(n) where red = 1, orange = 2, ..., magenta = 8.
%H Michael De Vlieger, <a href="/A361444/a361444_1.png">Log log scatterplot of a(n)</a>, n = 1..10^4, with a color function showing a(n) mod 10, where red = 1, orange = 2, ..., magenta = 9.
%e a(10) = 22, the smallest unused positive palindrome which can be added to a(9) = 9 to get a prime; 9 + 22 = 31.
%t nn = 60; kk = 5*10^4; c[_] = False; a[1] = j = 1; c[1] = True; u = 2;
%t MapIndexed[Set[s[First[#2]], #1] &, Select[Range[kk], PalindromeQ]];
%t Do[k = u; While[Or[c[k], CompositeQ[s[k] + j]], k++];
%t Set[{a[n], c[k], j}, {k, True, s[k]}];
%t If[k == u, While[c[u], u++]], {n, 2, nn}];
%t Array[s @* a, nn] (* _Michael De Vlieger_, Mar 18 2023 *)
%o (Python)
%o from sympy import isprime
%o from itertools import count, islice, product
%o def pals(): # generator of palindromes
%o digits = "0123456789"
%o for d in count(1):
%o for p in product(digits, repeat=d//2):
%o if d > 1 and p[0] == "0": continue
%o left = "".join(p); right = left[::-1]
%o for mid in [[""], digits][d%2]:
%o yield int(left + mid + right)
%o def agen(): # generator of terms of sequence
%o pg, passed = pals(), []
%o an = next(p for p in pg if p > 0) # start at 1
%o while True:
%o yield an
%o for p in passed:
%o if isprime(an+p):
%o passed.remove(p)
%o break
%o else:
%o while not isprime(an + (p:=next(pg))):
%o passed.append(p)
%o an = p
%o print(list(islice(agen(), 57))) # _Michael S. Branicky_, Mar 12 2023
%o (PARI) nextpal(k) = my(d=digits(k)); while (d!=Vecrev(d), k++; d = digits(k)); k;
%o lista(nn) = my(va = vector(nn)); va[1] = 1; for (n=2, nn, my(k=1); while(!isprime(va[n-1]+k) || #select(x->(x==k), va), k=nextpal(k+1)); va[n] = k;); va; \\ _Michel Marcus_, Mar 19 2023
%Y Cf. A002113, A082979.
%K base,nonn
%O 1,2
%A _Jodi Spitz_, Mar 12 2023
%E a(25) and beyond from _Michael S. Branicky_, Mar 12 2023