This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A350574 #33 Oct 23 2024 20:28:03 %S A350574 131,197,373,419,571,593,617,839,919,1297,1327,1429,1879,1949,1993, %T A350574 2129,2213,2591,3539,4337,4637,4639,5519,6619,8389,8933,11491,11519, %U A350574 11527,11597,11897,11969,12757,12829,12979,13649,13879,14537,14737,14741,14891 %N A350574 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 A350574 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 A350574 Chai Wah Wu, <a href="/A350574/b350574.txt">Table of n, a(n) for n = 1..10000</a> %e A350574 131 is prime, and so are asc(131) = 113 and desc(131) = 311. Further, these are all distinct primes. %e A350574 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 A350574 d:= n-> convert(n, base, 10): %p A350574 g:= (n, r)-> parse(cat(sort(d(n), r)[])): %p A350574 f:= n-> (s-> nops(s)=3 and andmap(isprime, s))({n, g(n, `<`), g(n, `>`)}): %p A350574 q:= n-> f(n) and n=min(select(f, map(x-> parse(cat(x[])), %p A350574 combinat[permute](d(n))))): %p A350574 select(q, [$1..15000])[]; # _Alois P. Heinz_, Jan 15 2022 %t A350574 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 A350574 (Python) %o A350574 import numpy as np %o A350574 # preliminary functions we will use in building our list %o A350574 def is_prime(n): %o A350574 for d in range(2,int(np.sqrt(n))+1): %o A350574 if n % d == 0: %o A350574 return False %o A350574 return True %o A350574 def asc(n): # returns integer with digits of n in ascending order %o A350574 n_list = [int(digit) for digit in str(n)] # separate digits of n into a list %o A350574 n_list.sort() # rearrange numbers in ascending order %o A350574 asc_n = int(''.join([str(digit) for digit in n_list])) # concatenate the sorted digits %o A350574 return asc_n %o A350574 def desc(n): # returns integer with digits of n in descending order %o A350574 n_list = [int(digit) for digit in str(n)] %o A350574 n_list.sort(reverse=True) %o A350574 desc_n = int(''.join([str(digit) for digit in n_list])) %o A350574 return desc_n %o A350574 N = 5 %o A350574 # get list of integers n such that n, asc(n), and desc(n) are all distinct primes %o A350574 condition_1 = [n for n in range(2,10**N) %o A350574 if is_prime(n) %o A350574 and is_prime(asc(n)) %o A350574 and is_prime(desc(n)) %o A350574 and n not in (asc(n),desc(n))] %o A350574 # refine so that our list includes only the minimum permutation of a given set of digits satisfying condition 1 %o A350574 condition_2 = [] %o A350574 for num in condition_1: %o A350574 if asc(num) not in [asc(n) for n in condition_2]: %o A350574 condition_2.append(num) %o A350574 print(condition_2) %o A350574 (Python) %o A350574 from itertools import count, islice, combinations_with_replacement %o A350574 from sympy import isprime %o A350574 from sympy.utilities.iterables import multiset_permutations %o A350574 def A350574_gen(): # generator of terms %o A350574 for l in count(1): %o A350574 rlist = [] %o A350574 for a in combinations_with_replacement('123456789',l): %o A350574 s = ''.join(a) %o A350574 p, q = int(s), int(s[::-1]) %o A350574 if p != q and isprime(p) and isprime(q): %o A350574 for b in multiset_permutations(a): %o A350574 r = int(''.join(b)) %o A350574 if p < r < q and isprime(r): %o A350574 rlist.append(r) %o A350574 break %o A350574 yield from sorted(rlist) %o A350574 A350574_list = list(islice(A350574_gen(),50)) # _Chai Wah Wu_, Feb 13 2022 %Y A350574 Cf. A009994. %Y A350574 Subsequence of A038618. %K A350574 nonn,base %O A350574 1,1 %A A350574 _William Riley Barker_, Jan 06 2022