def one_list_to_n_numbers(l): # 9 or 10 """Starting with the pattern list, yield all the valid numbers that it generates""" start = 1 if (l[0] == 'X') else 0 for i in range(start, 10): mod_l = [i if (j == 'X') else j for j in l] num = digit_list_to_num(mod_l) yield num max_num_prime = 0 for pattern in candidate_generator(): actual_primes = [] not_prime = 0 num_prime = 0 for possible_prime in one_list_to_n_numbers(pattern): if is_prime(possible_prime): num_prime += 1 actual_primes.append(possible_prime) else: not_prime += 1 if not_prime >= 10 - max_num_prime: break if num_prime > max_num_prime: max_num_prime = num_prime print pattern, actual_primes, num_prime if num_prime >= 8: print "====" print actual_primes[0] break
# Copied from 28, and modified. # Calculate only the diagonal entries. from poiler_common import is_prime prev_n = 1 step = 2 prime_count, diagonal_count = 0,1 while True: for j in xrange(4): n = prev_n + step if is_prime(n): prime_count += 1 prev_n = n diagonal_count += 4 step += 2 if prime_count * 10 < diagonal_count: break print step-1