%I #21 Jan 18 2023 15:58:05
%S 13,17,37,79,107,113,127,131,137,139,149,157,163,167,173,179,181,191,
%T 197,199,239,241,251,277,281,283,313,337,347,349,359,367,373,379,389,
%U 397,419,457,461,463,467,479,491,563,569,571,577,587,593,613
%N Primes p which have at least one prime anagram larger than p.
%C Primes like 113, 137, 149, 157 etc have more than one such larger anagram, but are only listed once.
%H R. J. Mathar, <a href="/A166681/b166681.txt">Table of n, a(n) for n = 1..1000</a>
%e 13 is the first with 31 as prime anagram.
%e 17 is the second with 71 as prime anagram.
%e 31 has one anagram 13 but this is not >31 so 31 is not in the sequence.
%p filter:= proc(p) local L,Lp,q,i;
%p if not isprime(p) then return false fi;
%p L:= convert(p,base,10);
%p for Lp in combinat:-permute(L) do
%p q:= add(Lp[i]*10^(i-1),i=1..nops(L));
%p if q > p and isprime(q) then return true fi
%p od;
%p false
%p end proc:
%p select(filter, [seq(i,i=13..1000,2)]); # _Robert Israel_, Jan 18 2023
%t paQ[n_]:=Length[Select[FromDigits/@Permutations[IntegerDigits[n]],#>n && PrimeQ[#]&]]>0; Select[Prime[Range[200]],paQ] (* _Harvey P. Dale_, Sep 23 2013 *)
%o (Python)
%o from itertools import islice
%o from sympy.utilities.iterables import multiset_permutations
%o from sympy import isprime, nextprime
%o def A166681_gen(): # generator of terms
%o p = 13
%o while True:
%o for q in multiset_permutations(str(p)):
%o if (r:=int(''.join(q)))>p and isprime(r):
%o yield p
%o break
%o p = nextprime(p)
%o A166681_list = list(islice(A166681_gen(),20)) # _Chai Wah Wu_, Jan 17 2023
%Y Cf. A055387, A109308, A069567.
%K nonn,base
%O 1,1
%A _Pierre CAMI_, Oct 18 2009
%E Definition clarified, sequence extended. - _R. J. Mathar_, Oct 12 2012
|