%I #11 Apr 16 2023 09:48:04
%S 23,37,53,73,113,127,131,137,139,151,157,173,179,193,197,211,223,229,
%T 233,239,241,271,283,293,311,313,317,331,337,347,353,359,367,373,379,
%U 383,389,397,421,431,433,457,523,541,547,571,593,613,617,631,673,677,719
%N Primes that can be written as the result of shuffling the decimal digits of two primes.
%C Each term is essentially an element of the shuffle product of the decimal digits of two primes (possibly equal).
%H Michael S. Branicky, <a href="/A361530/b361530.txt">Table of n, a(n) for n = 1..10000</a>
%H John D. Cook, <a href="https://www.johndcook.com/blog/2023/03/13/shuffle-product/">Shuffle product</a>.
%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Shuffle_algebra#Shuffle_product">Shuffle product</a>.
%e 37 and 73 are in the sequence because they are both the result of shuffling 3 and 7.
%e 127 is in the sequence because it is the result of shuffling 2 and the digits of 17.
%e 1193 is in the sequence because it is the result of shuffling the digits of 13 and the digits of 19.
%e 163 is not in the sequence because it is not the result of shuffling the digits of two primes. 163 is the result of permuting the digits of 3 and 61; however, 163 contains the digits of 61 in the wrong order.
%o (Python)
%o import sympy
%o def get_shuffle_product(list_1, list_2):
%o shuffle_product = set()
%o shuffle = []
%o _get_shuffle_product(list_1, list_2, shuffle, shuffle_product)
%o return shuffle_product
%o def _get_shuffle_product(list_1, list_2, shuffle, shuffle_product):
%o if len(list_1) == 0 and len(list_2) == 0:
%o shuffle_product.add(tuple(shuffle))
%o return
%o else:
%o if len(list_1) == 0:
%o shuffle.append(list_2[0])
%o _get_shuffle_product(list_1, list_2[1:], shuffle, shuffle_product)
%o shuffle.pop()
%o elif len(list_2) == 0:
%o shuffle.append(list_1[0])
%o _get_shuffle_product(list_1[1:], list_2, shuffle, shuffle_product)
%o shuffle.pop()
%o else:
%o shuffle.append(list_1[0])
%o _get_shuffle_product(list_1[1:], list_2, shuffle, shuffle_product)
%o shuffle.pop()
%o shuffle.append(list_2[0])
%o _get_shuffle_product(list_1, list_2[1:], shuffle, shuffle_product)
%o shuffle.pop()
%o max_prime_index = 25 # one and two digit primes.
%o max_element = 999
%o prime_set = set()
%o for p_index in range(1, max_prime_index+1):
%o p = sympy.prime(p_index)
%o for q_index in range(p_index, max_prime_index+1):
%o q = sympy.prime(q_index)
%o list_p = list(str(p))
%o list_q = list(str(q))
%o shuffle_product = get_shuffle_product(list_p, list_q)
%o for s in shuffle_product:
%o candidate = int(''.join(s))
%o if sympy.isprime(candidate) and candidate <= max_element:
%o prime_set.add(candidate)
%o print(sorted(prime_set))
%o (Python)
%o from sympy import isprime
%o from itertools import chain, combinations
%o def powerset(s): # skipping empty set and entire set
%o return chain.from_iterable(combinations(s, r) for r in range(1, len(s)))
%o def ok(n):
%o if not isprime(n): return False
%o s = str(n)
%o for indices in powerset(range(len(s))):
%o t1 = "".join(s[i] for i in indices)
%o t2 = "".join(s[i] for i in range(len(s)) if i not in indices)
%o if t1[0] != "0" and t2[0] != "0" and isprime(int(t1)) and isprime(int(t2)):
%o return True
%o print([k for k in range(720) if ok(k)]) # _Michael S. Branicky_, Apr 16 2023
%Y Cf. A019549, A083427, A105184.
%K nonn,base
%O 1,1
%A _Robert C. Lyons_, Mar 14 2023
|