def is_pandigital(n): second = number.is_pandigital(str(n % 1000000000)) if not second: return False while n > 1000000000000000: n = n // 1000000 while n > 1000000000: n = n // 10 return number.is_pandigital(str(n))
def solve(): result = 0 #@UnusedVariable pandigital_concatenated_products = [] # since n > 1, 5 digits are enough for m in range (1,10**5): for n in range(1,10): p = concatenated_product(m, range(1, n+1)) if len(str(p)) > 9: break if is_pandigital(p, 9): pandigital_concatenated_products.append(p) result = sorted(pandigital_concatenated_products)[-1] print("The largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 is %(result)d" % vars())
def solve(): # log_10(a) + log_10(b) + log_10(c) <= 9 # ==> 2*log_10(ab) <= 9 # ==> log_10(b) <= 4.5 - log_10(a) pandigital_products = [] for a in range(1, int(4.5**10)+1): for b in range(1, int((4.5**10)/a)+1): c = a*b pandigital_candidate = str(a)+str(b)+str(c) if len(pandigital_candidate) == 9 and is_pandigital(pandigital_candidate): pandigital_products.append((a, b, c)) print(pandigital_products) result = sum(set([c for (a,b,c) in pandigital_products])) #@UnusedVariable print("The sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital is %(result)d" % vars())
import number largest = 0 for n in range(1, 100000): for limit in range(1, 11): triple = [i * n for i in range(1, limit)] concat = "".join(str(i) for i in triple) if number.is_pandigital(concat): concat = int(concat) if concat > largest: largest = concat print("Largest concatination: {}".format(largest))
import number products = set() for a in range(100): if '0' in str(a): continue for b in range(9876): if '0' in str(b): continue product = a * b if number.is_pandigital(str(product) + str(a) + str(b)): products.add(product) print("Sum of products: {}".format(sum(products)))