def challenge041(): # loop through number of digits highest = 0 for n in [4, 7]: chars = string.join([str(c) for c in xrange(1, n + 1)], "") for potential in [int(p) for p in permutate(chars) if isPrime(int(p))]: if potential > highest: highest = potential return highest
def challenge032(): source = "123456789" products = [] for potential in [int(p) for p in permutate(source)]: # * can be after 1, 2, 3, 4 # = can only be between 5 and 6 third = potential % 10**4 for i in xrange(1, 3): first = potential // 10**(9 - i) second = (potential // 10**(4)) % 10**(5 - i) product = first * second if product == third: products.append(third) return sum(set(products))
def challenge043(): source = "0123456789" total = 0 for n in [int(n) for n in permutate(source) \ if int(n) >= 1000000000 and \ int(n[1:4]) % 2 == 0 and \ int(n[2:5]) % 3 == 0 and \ int(n[3:6]) % 5 == 0 and \ int(n[4:7]) % 7 == 0 and \ int(n[5:8]) % 11 == 0 and \ int(n[6:9]) % 13 == 0 and \ int(n[7:10]) % 17 == 0]: total += n return total
def challenge024(): number = "0123456789" permutations = (s for s in permutate(number)) millionth = -1 millionth = [n for n, i in zip(permutations, xrange(1000000)) if i == 999999] return int(millionth[0])