(Python)
import sympy
def get_shuffle_product(list_1, list_2):
shuffle_product = set()
shuffle = []
_get_shuffle_product(list_1, list_2, shuffle, shuffle_product)
return shuffle_product
def _get_shuffle_product(list_1, list_2, shuffle, shuffle_product):
if len(list_1) == 0 and len(list_2) == 0:
shuffle_product.add(tuple(shuffle))
return
else:
if len(list_1) == 0:
shuffle.append(list_2[0])
_get_shuffle_product(list_1, list_2[1:], shuffle, shuffle_product)
shuffle.pop()
elif len(list_2) == 0:
shuffle.append(list_1[0])
_get_shuffle_product(list_1[1:], list_2, shuffle, shuffle_product)
shuffle.pop()
else:
shuffle.append(list_1[0])
_get_shuffle_product(list_1[1:], list_2, shuffle, shuffle_product)
shuffle.pop()
shuffle.append(list_2[0])
_get_shuffle_product(list_1, list_2[1:], shuffle, shuffle_product)
shuffle.pop()
max_prime_index = 25 # one and two digit primes.
max_element = 999
prime_set = set()
for p_index in range(1, max_prime_index+1):
p = sympy.prime(p_index)
for q_index in range(p_index, max_prime_index+1):
q = sympy.prime(q_index)
list_p = list(str(p))
list_q = list(str(q))
shuffle_product = get_shuffle_product(list_p, list_q)
for s in shuffle_product:
candidate = int(''.join(s))
if sympy.isprime(candidate) and candidate <= max_element:
prime_set.add(candidate)
print(sorted(prime_set))
(Python)
from sympy import isprime
from itertools import chain, combinations
def powerset(s): # skipping empty set and entire set
return chain.from_iterable(combinations(s, r) for r in range(1, len(s)))
def ok(n):
if not isprime(n): return False
s = str(n)
for indices in powerset(range(len(s))):
t1 = "".join(s[i] for i in indices)
t2 = "".join(s[i] for i in range(len(s)) if i not in indices)
if t1[0] != "0" and t2[0] != "0" and isprime(int(t1)) and isprime(int(t2)):
return True
|