login
A361444
Lexicographically earliest sequence of distinct positive base-10 palindromes such that a(n) + a(n+1) is prime.
2
1, 2, 3, 4, 7, 6, 5, 8, 9, 22, 141, 88, 111, 202, 55, 222, 11, 212, 99, 232, 121, 252, 101, 66, 131, 242, 191, 272, 77, 282, 151, 292, 171, 262, 181, 606, 313, 414, 343, 444, 353, 44, 303, 424, 33, 434, 323, 404, 383, 474, 535, 484, 373, 454, 333, 464, 363
OFFSET
1,2
LINKS
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
Sequence in context: A085162 A182178 A326316 * A305417 A231550 A106453
KEYWORD
base,nonn
AUTHOR
Jodi Spitz, Mar 12 2023
EXTENSIONS
a(25) and beyond from Michael S. Branicky, Mar 12 2023
STATUS
approved