A380227 Beginning with 11, least prime such that concatenation of first n terms and its digit reversal both are primes.
11, 3, 11, 31, 59, 463, 131, 103, 599, 3253, 7649, 439, 12791, 2953, 17321, 16651, 10007, 51787, 4871, 1483, 6857, 15649, 53051, 61441, 84449, 35533, 19913, 39097, 23081, 206527, 44939, 189517, 32369, 106657, 606899, 117703, 222977, 220903, 69779, 12007, 95063, 136471, 43973
Offset: 1
Programs
-
Maple
rev:= proc(n) local L,i; L:= convert(n,base,10); add(L[-i]*10^(i-1),i=1..nops(L)) end proc: tcat:= proc(a,b) a*10^(1+ilog10(b))+b end proc: A:= 11: x:= 11: for i from 1 to 50 do p:= 2: do p:= nextprime(p); y:= tcat(x,p); if isprime(y) and isprime(rev(y)) then A:= A,p; x:= y; break fi; od od: A; # after Robert Israel in A113584
-
Mathematica
w={11};Do[k=1;q=Monitor[Parallelize[While[True,If[PrimeQ[FromDigits[Join@@IntegerDigits/@Reverse[IntegerDigits[FromDigits[Join@@IntegerDigits/@Append[w,Prime[k]]]]]]]&&PrimeQ[FromDigits[Join@@IntegerDigits/@Append[w,Prime[k]]]],Break[]];k++];Prime[k]],{i,k}];w=Append[w,q],{i,2,50}];w
-
Python
from itertools import count, islice from gmpy2 import digits, is_prime, mpz, next_prime def agen(): # generator of terms s, r, an = "", "", 11 while True: yield int(an) d = digits(an) s, r, p, sp = s+d, d[::-1]+r, 3, "3" while not is_prime(mpz(s+sp)) or not is_prime(mpz(sp[::-1]+r)): p = next_prime(p) sp = digits(p) an = p print(list(islice(agen(), 40))) # after Michael S. Branicky in A113584