def odd_divisible_pandigitals(): small_primes = prime_sieve(20) def sub_divides(number): if all( sub % prime == 0 for sub, prime in izip(substring_numbers(number,3,1),cycle(small_primes)) ): return True return False for pandigital in ifilter(sub_divides,pandigitals(10)): yield pandigital
def smallest_odd_composite(): def odd_numbers(start=1): num = start while True: yield num num += 2 primes = set(prime_sieve(10000)) odd_composites = ( i for i in odd_numbers(9) if i not in primes and i < 10000) for n in odd_composites: if any( (n - (2 * base ** 2)) in primes for base in xrange(1, (int(sqrt((n-2)/2))+1)) ): continue return n
def largest_prime_seq(limit): primes = prime_sieve(limit) prime_set = set(primes) # determine the maximum allowable sequence length test_num = 0 for max_seq_len, prime in enumerate(primes): test_num += prime if test_num > limit: break for length in xrange(max_seq_len,0,-1): for start in xrange(len(primes)-length): seq = primes[start:start+length] seq_sum = sum(seq) if seq_sum >= limit: break if seq_sum in prime_set: return seq
# sum for a set of four primes with this property. # # Find the lowest sum for a set of five primes for which any two # primes concatenate to produce another prime. from itertools import dropwhile from collections import defaultdict from math import floor, log10 from p010 import prime_sieve from p049 import is_prime import psyco psyco.full() primes = prime_sieve(100000) primes.remove(2) # Can never be in a set of more than one primes.remove(5) # Can never be in a set of more than one whitelist = defaultdict(set) blacklist = defaultdict(set) good_sets = defaultdict(list) def is_concatenable_pair(x, y): # if y in blacklist[x]: # return False if y in whitelist[x]: return True if not (is_concatenable_combo(x, y) and is_concatenable_combo(y, x)): blacklist[x].add(y) return False