OFFSET
1,2
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..10000
Michael De Vlieger, Log log scatterplot of a(n), n = 1..10^4, with a color function showing number of decimal digits of a(n) where red = 1, orange = 2, ..., magenta = 8.
Michael De Vlieger, Log log scatterplot of a(n), n = 1..10^4, with a color function showing a(n) mod 10, where red = 1, orange = 2, ..., magenta = 9.
EXAMPLE
a(10) = 22, the smallest unused positive palindrome which can be added to a(9) = 9 to get a prime; 9 + 22 = 31.
MATHEMATICA
nn = 60; kk = 5*10^4; c[_] = False; a[1] = j = 1; c[1] = True; u = 2;
MapIndexed[Set[s[First[#2]], #1] &, Select[Range[kk], PalindromeQ]];
Do[k = u; While[Or[c[k], CompositeQ[s[k] + j]], k++];
Set[{a[n], c[k], j}, {k, True, s[k]}];
If[k == u, While[c[u], u++]], {n, 2, nn}];
Array[s @* a, nn] (* Michael De Vlieger, Mar 18 2023 *)
PROG
(Python)
from sympy import isprime
from itertools import count, islice, product
def pals(): # generator of palindromes
digits = "0123456789"
for d in count(1):
for p in product(digits, repeat=d//2):
if d > 1 and p[0] == "0": continue
left = "".join(p); right = left[::-1]
for mid in [[""], digits][d%2]:
yield int(left + mid + right)
def agen(): # generator of terms of sequence
pg, passed = pals(), []
an = next(p for p in pg if p > 0) # start at 1
while True:
yield an
for p in passed:
if isprime(an+p):
passed.remove(p)
break
else:
while not isprime(an + (p:=next(pg))):
passed.append(p)
an = p
print(list(islice(agen(), 57))) # Michael S. Branicky, Mar 12 2023
(PARI) nextpal(k) = my(d=digits(k)); while (d!=Vecrev(d), k++; d = digits(k)); k;
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
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Jodi Spitz, Mar 12 2023
EXTENSIONS
a(25) and beyond from Michael S. Branicky, Mar 12 2023
STATUS
approved