from tools import number_theory def shift(num): left = str(num)[:-1] while left: yield int(left) left = left[:-1] right = str(num)[1:] while right: yield int(right) right = right[1:] def check_prime(x): x = str(x) if ('9' == x[0]) or ('9' == x[-1]): return False if ('1' == x[0]) or ('1' == x[-1]): return False if '5' in x[1:]: return False if '2' in x[1:]: return False if '0' in x: return False if '4' in x: return False if '6' in x: return False if '8' in x: return False return True def search(): find = [] prime = list(number_theory.make_prime(1000000)) for p in filter(lambda x: check_prime(x), prime): for s in shift(p): if s not in prime: break else: find.append(p) return find[4:] print(sum(search()))