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(): for power in euler_util.numbers(): start = 10**power cache = {} for i in range(start, int(math.ceil(10**(power + 1) / 6.0))): try: try: base_digs = cache[i] except KeyError: base_digs = euler_util.digits(i) base_digs.sort() cache[i] = base_digs for x in range(2, 7): val = x * i try: digs = cache[val] except KeyError: digs = euler_util.digits(val) digs.sort() cache[val] = digs if not digs == base_digs: raise Exc print i return except Exc: pass
def run(): primes = prime_reader.read_primes_default() last_prime = primes.next() prime_count = 0 diag_total = 1 current = 1 for ring in eu.numbers(2): incr = (ring - 1) * 2 for corner in xrange(3): current = op.iadd(current, incr) while current > last_prime: last_prime = primes.next() if current == last_prime: prime_count = op.iadd(prime_count, 1) current = op.add(current, incr) diag_total = op.iadd(diag_total, 4) perc = op.div(float(prime_count), diag_total) # print ring, side_length(ring), last_prime, diag_total, perc if op.lt(perc, 0.1): return side_length(ring)
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(): count = 0 for p in range(1,22): for x in eu.numbers(1): l = eu.length(pow(x,p)) if l > p: break if l == p: count += 1 return count
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(): sum = 0 for n in range(23, 101): rgen = euler_util.numbers(1, 1, n + 1) try: while combos(n, rgen.next()) <= 1000000: pass sum += 1 while combos(n, rgen.next()) > 1000000: sum += 1 except StopIteration: pass
def run(): vals = [] for i in euler_util.numbers(1): factors = [p for p in euler_util.prime_factors(i)] if len(factors) == 4: vals.append(i) print vals if len(vals) == 4: print vals return else: vals = []
import euler_util def complete(x): y = x[:] y.sort() return y == range(1, 10) max_val = 0 for digits in euler_util.permutations(range(1,10), 4): base_value = euler_util.undigits(digits) for i in euler_util.numbers(2): curr_value = base_value * i digits += euler_util.digits(curr_value) if len(digits) > 9: break elif len(digits) == 9: if complete(digits): val = euler_util.undigits(digits) # print base_value,i,val if val > max_val: max_val = val break # print max_val
def run(): for n in eu.numbers(): p = partitions(n) if p % 1000000 == 0: return n
def twice_squares(): for i in euler_util.numbers(1): yield 2 * (i**2)