def run(target=8): pgen = eu.GenFinder(eu.gen_primes()) # Loop over all prime numbers for prime_idx in eu.numbers(): curr_prime = pgen[prime_idx] curr_digits = eu.digits(curr_prime) # digits in current prime # Get all selections of indices from current digits for rindices in eu.selections(range(len(curr_digits))): rzero = 0 in rindices if len(rindices) == 0: continue found_primes = [] work_digs = curr_digits[:] # copy digits of current prime # Choose the digit which we will insert at each index in rindices (the current selection) for replacement in range(10): if replacement == 0 and rzero: continue for rindex in rindices: work_digs[rindex] = replacement prime_idx = pgen.find(eu.undigits(work_digs)) if prime_idx != -1: found_primes.append(pgen[prime_idx]) if len(found_primes) >= target: # print "answer =",min(found_primes),found_primes,rindices return min(found_primes)
def run(): ts = euler_util.GenFinder(twice_squares()) primes = euler_util.GenFinder(euler_util.gen_primes()) for i in euler_util.numbers(9, 2): if primes.contains(i): continue if not find_sum(i, ts, primes): print i return
def run(): pgen = euler_util.gen_primes() # initialize primes list with single-digit primes...we don't consider those for rotation primes = [pgen.next(), pgen.next(), pgen.next(), pgen.next()] results = [] while len(results) < 11: prime = pgen.next() primes.append(prime) if curious(prime, primes): print prime results.append(prime) print sum(results)
import euler_util def f(n, a, b): return (n ** 2) + (a * n) + b prime_gen = euler_util.gen_primes() primes = [prime_gen.next() for i in range(1000)] def count_primes(a, b): sum = 0 for n in euler_util.numbers(): val = f(n, a, b) while val > primes[-1]: primes.append(prime_gen.next()) if not val in primes: return sum sum += 1 def run(): max_count = 0 max_a = 0 max_b = 0 for a in range(-999, 1000): for b in range(-999, 1000): count = count_primes(a, b) if count > max_count: