login
Lexicographically earliest rearrangement of primes such that the sum of two consecutive terms is a palindrome.
2

%I #15 Dec 04 2018 17:21:29

%S 2,3,5,17,71,131,101,151,61,181,31,13,53,149,73,139,83,179,23,43,199,

%T 457,7,37,29,59,163,79,173,89,113,109,103,311,547,271,11,191,41,47,19,

%U 193,211,223,241,233,251,557,281,577,5869,137,277,127,307,97,317,107

%N Lexicographically earliest rearrangement of primes such that the sum of two consecutive terms is a palindrome.

%H Ivan Neretin, <a href="/A082979/b082979.txt">Table of n, a(n) for n = 1..10000</a>

%t seq={2}; Do[k=3; While[MemberQ[seq, k] || !PalindromeQ[k+seq[[-1]]], k = NextPrime[k]]; AppendTo[seq, k], {i, 1, 50}]; seq (* _Amiram Eldar_, Dec 04 2018 *)

%o (PARI)

%o ispal(n)={my(v=digits(n));for(i=1, #v\2, if(v[i]<>v[#v+1-i], return(0))); 1}

%o seq(n)={my(v=vector(n), M=Map(), t=0); for(n=1, n, forprime(p=1, oo, if(!mapisdefined(M,p) && ispal(p+t), t=p; break)); mapput(M,t,1); v[n]=t); v} \\ _Andrew Howroyd_, Dec 04 2018

%K base,nonn,look

%O 1,1

%A _Jason Earls_, May 28 2003