# VEEEEEEEEEEEERY SLOW. Over 1hr, but gets correct solution. from Functions import runtime, import_csv import time, functools global primes_ls def factors(n): facts = set(functools.reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) return len(facts) start_time = time.clock() primes_ls = import_csv('primes_1e7.csv') primes_ls = primes_ls[0] for prime in primes_ls: prime = int(prime) sum = 0 last_div = factors(10000001) for num in range(10000000, 1, -1): current = factors(num) if last_div == current: sum +=1 last_div = current if num % 1000000 == 0: print('Current number under test is ', num) print('desired num is ', sum) runtime(start_time)
digits = list(digits) for i in range(len(digits)): digits[i] = int(digits[i]) return digits start = time.clock() digits = [] ls_of_products = [] sum_of_products = 0 for i in range(2, 100): for j in range(2, 10000): test_prod = i * j if test_prod in ls_of_products: continue test_list = build_digits(test_prod, i, j) if is_pandigital(test_list): sum_of_products += test_prod ls_of_products.append(test_prod) if i % 100 == 0: print("Current i is: ", i) print("The sum of products is ", sum_of_products) runtime(start)