login
Do-si-do primes: primes that remain prime when their digits, taken by pairs, are reversed (see comments for more details).
1

%I #14 Mar 16 2019 13:15:15

%S 11,13,17,31,37,71,73,79,97,113,131,149,151,157,167,179,181,191,199,

%T 311,313,337,347,353,359,373,383,389,727,733,739,743,751,757,761,769,

%U 787,797,919,929,937,941,953,967,971,983,991,1117,1171,1213,1231,1297

%N Do-si-do primes: primes that remain prime when their digits, taken by pairs, are reversed (see comments for more details).

%C Primes n with an even number of digits are included if (a) a prime results after reversing n's digits by pairs, e.g., 8971 is a prime and is included because 9817 is also a prime, and (b) n's second digit is not zero. Primes with an odd number of digits are included if (a) a prime results after extracting the middle digit of n, reversing the rest of n's digits by pairs, and inserting the middle digit of n back into the middle of the resulting digits, e.g., 1358471 is a prime and is included because 3148517 is also a prime, and (b) n's second digit is not zero.

%H Harvey P. Dale, <a href="/A266675/b266675.txt">Table of n, a(n) for n = 1..1000</a>

%t dsdQ[n_/;EvenQ[IntegerLength[n]]]:=Module[{idn=IntegerDigits[n]}, idn[[2]] != 0&&PrimeQ[FromDigits[Flatten[Reverse/@Partition[idn,2]]]]]; dsdQ[ n_/;OddQ[ IntegerLength[n]]]:=Module[{idn=IntegerDigits[n], len = (IntegerLength[ n]-1)/2,t,fr,ls,md},t=TakeDrop[idn,len];fr=t[[1]];ls=Rest[ t[[2]]];md=First[t[[2]]];idn[[2]]!=0&&PrimeQ[FromDigits[ Insert[ Flatten[Reverse/@Partition[Join[fr,ls],2]],md,len+1]]]]; Select[Prime[Range[5,500]],dsdQ] (* The program uses the TakeDrop function from Mathematica version 10 *)

%o (Perl) use ntheory ":all"; sub is_a266675 { my $n = shift; my @d=todigits($n); return unless is_prime($n) && $d[1] != 0; my $middle = (@d & 1) ? splice(@d,@d>>1,1) : undef; my @r = @d[map {$_^1} 0..$#d]; splice(@r,@r>>1,0,$middle) if defined $middle; is_prime(fromdigits(\@r)); } # _Dana Jacobsen_, Jan 03 2016

%K nonn,base

%O 1,1

%A _Harvey P. Dale_, Jan 02 2016