Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations, combinations
- def is_prime(num):
- for i in range(2, int(num ** 0.5) + 1):
- if num % i == 0:
- return False
- return True
- def propagate(cur_nums, level=0):
- if level == 5:
- print(cur_nums)
- if sum(cur_nums) < propagate.min:
- propagate.min = sum(cur_nums)
- for num in pairs:
- if num not in cur_nums:
- valid = True
- for i in cur_nums:
- if num not in pairs[i]:
- valid = False
- break
- if valid:
- lst = list(cur_nums)
- lst.append(num)
- propagate(lst, level + 1)
- propagate.min = 100**100
- primes = [x for x in range(2, 10000) if is_prime(x)]
- cur_min = 100**100
- pairs = {key: [] for key in primes}
- for a, b in combinations(primes, 2):
- if is_prime(int(str(a) + str(b))) and is_prime(int(str(b) + str(a))):
- pairs[a].append(b)
- pairs[b].append(a)
- propagate([])
- print(propagate.min)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement