%I #33 Oct 23 2024 20:28:03
%S 131,197,373,419,571,593,617,839,919,1297,1327,1429,1879,1949,1993,
%T 2129,2213,2591,3539,4337,4637,4639,5519,6619,8389,8933,11491,11519,
%U 11527,11597,11897,11969,12757,12829,12979,13649,13879,14537,14737,14741,14891
%N Primes p such that p, asc(p), and desc(p) are all distinct primes (where asc(p) and desc(p) are the digits of p in ascending and descending order, respectively) and p is the minimum of all permutations of its digits with this property.
%C All terms in this sequence are zero-free: If p contained 0 as a digit, then desc(p) would end with the zero digit, making it divisible by 10 (thus composite).
%H Chai Wah Wu, <a href="/A350574/b350574.txt">Table of n, a(n) for n = 1..10000</a>
%e 131 is prime, and so are asc(131) = 113 and desc(131) = 311. Further, these are all distinct primes.
%e 419, asc(419) = 149, and desc(419) = 941 are all distinct primes, and 419 is the smallest permutation of the digits {1,4,9} with this property (149 is not included because asc(149) = 149, so these would not be distinct; 491 is not included because 419 < 491 with the same set of digits).
%p d:= n-> convert(n, base, 10):
%p g:= (n, r)-> parse(cat(sort(d(n), r)[])):
%p f:= n-> (s-> nops(s)=3 and andmap(isprime, s))({n, g(n, `<`), g(n, `>`)}):
%p q:= n-> f(n) and n=min(select(f, map(x-> parse(cat(x[])),
%p combinat[permute](d(n))))):
%p select(q, [$1..15000])[]; # _Alois P. Heinz_, Jan 15 2022
%t Select[Prime@Range@2000,AllTrue[FromDigits/@{s=Sort[d=IntegerDigits@#],Reverse@s},PrimeQ]&&Min@Most@Rest@Sort@Select[FromDigits/@Permutations[d],PrimeQ]==#&] (* _Giorgos Kalogeropoulos_, Jan 16 2022 *)
%o (Python)
%o import numpy as np
%o # preliminary functions we will use in building our list
%o def is_prime(n):
%o for d in range(2,int(np.sqrt(n))+1):
%o if n % d == 0:
%o return False
%o return True
%o def asc(n): # returns integer with digits of n in ascending order
%o n_list = [int(digit) for digit in str(n)] # separate digits of n into a list
%o n_list.sort() # rearrange numbers in ascending order
%o asc_n = int(''.join([str(digit) for digit in n_list])) # concatenate the sorted digits
%o return asc_n
%o def desc(n): # returns integer with digits of n in descending order
%o n_list = [int(digit) for digit in str(n)]
%o n_list.sort(reverse=True)
%o desc_n = int(''.join([str(digit) for digit in n_list]))
%o return desc_n
%o N = 5
%o # get list of integers n such that n, asc(n), and desc(n) are all distinct primes
%o condition_1 = [n for n in range(2,10**N)
%o if is_prime(n)
%o and is_prime(asc(n))
%o and is_prime(desc(n))
%o and n not in (asc(n),desc(n))]
%o # refine so that our list includes only the minimum permutation of a given set of digits satisfying condition 1
%o condition_2 = []
%o for num in condition_1:
%o if asc(num) not in [asc(n) for n in condition_2]:
%o condition_2.append(num)
%o print(condition_2)
%o (Python)
%o from itertools import count, islice, combinations_with_replacement
%o from sympy import isprime
%o from sympy.utilities.iterables import multiset_permutations
%o def A350574_gen(): # generator of terms
%o for l in count(1):
%o rlist = []
%o for a in combinations_with_replacement('123456789',l):
%o s = ''.join(a)
%o p, q = int(s), int(s[::-1])
%o if p != q and isprime(p) and isprime(q):
%o for b in multiset_permutations(a):
%o r = int(''.join(b))
%o if p < r < q and isprime(r):
%o rlist.append(r)
%o break
%o yield from sorted(rlist)
%o A350574_list = list(islice(A350574_gen(),50)) # _Chai Wah Wu_, Feb 13 2022
%Y Cf. A009994.
%Y Subsequence of A038618.
%K nonn,base
%O 1,1
%A _William Riley Barker_, Jan 06 2022