def potential_truncatable_primes(): begin_digits = (2,3,4,5,7) middle_digits = (1,3,7,9) end_digits = (3,7) for i in count(): for num in [ render_to_number(seq) for seq in [ (beg,) + mid + (end,) for beg in begin_digits for mid in product(middle_digits, repeat=i) for end in end_digits ] ]: yield num
def pandigitals(length): if length > 10: raise Exception('Pandigital number cannot be longer than 10 digits.') if length < 10: digits = range(1,length+1) else: digits = range(length) for perm in ifilter(lambda x: x[0] != 0, permutations(digits)): if perm[0] == 0: continue yield render_to_number(perm)
def pandigital_concat_products(): start_set = set(range(1,10)) for i in xrange(1,100000): remaining = start_set.copy() seq = [] for n in xrange(1,10): product = i * n product_list = [ int(digit) for digit in str(product) ] product_set = set(product_list) if len(product_list) != len(product_set): break if product_set <= remaining: remaining -= product_set seq += product_list else: break if len(remaining) == 0: yield (i, render_to_number(seq)) break