# Problem 41 # # We shall say that an n-digit number is pandigital if it makes use of # all the digits 1 to n exactly once. For example, 2143 is a 4-digit # pandigital and is also prime. # # What is the largest n-digit pandigital prime that exists? import eutils.primes as primes import eutils.strings as strings import time start = time.time() m = 9 found = False while not found: digits = list(range(m - 1, 0, -1)) perms = [int(str(m) + x) for x in strings.l_collapse(strings.l_permute(digits))] p = [x for x in perms if primes.is_prime(x)] if len(p): found = True m -= 1 ans = p[0] end = time.time() print("The answer to Problem 41 is: %s" % ans) print("<< Returned in %s seconds >>" % (end - start))
# Problem 24 # # A permutation is an ordered arrangement of objects. For example, 3124 # is one possible permutation of the digits 1, 2, 3 and 4. If all of the # permutations are listed numerically or alphabetically, we call it # lexicographic order. The lexicographic permutations of 0, 1 and 2 are: # # 012 021 102 120 201 210 # # What is the millionth lexicographic permutation of the digits 0, 1, 2, # 3, 4, 5, 6, 7, 8 and 9? import eutils.strings as strings import time start = time.time() n = 1000000 digits = list('0123456789') ans = int(strings.l_collapse([strings.l_permute(digits)[n - 1]])[0]) end = time.time() print("The answer to Problem 24 is: %s" % ans) print("<< Returned in %s seconds >>" % (end - start))