<jupyter_start><jupyter_text>Pandigital products 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, the 5-digit number, 15234, is 1 through 5 pandigital.The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum. ---  Idea Assume first multiplier takes $ i $ digits, second multiplier takes $ j $ digits, then product takes $ 9-i-j $ digits.The minimum product is $ 10^{i+j-2} $, and maximum product is $ 10^{i+j} $, so we get $ i+j-2 \le 9-(i+j) \le i+j $, so $ i+j = 5 $.Get all permutations of digits 1 through 9, and check if could get pandigital product. ---<jupyter_code>from itertools import permutations
def get_number(p, slc):
    return int(''.join(map(str, p[slc])))
get_number(range(1, 10), slice(0, 2))
get_number(range(1, 10), slice(5, 9))
def solve():
    s = 0
    pandigital_products = []
    for p in permutations(range(1, 10), 9):
        for i in [1, 2]:
            if get_number(p, slice(5, 9)) not in pandigital_products and \
            get_number(p, slice(0, i)) * get_number(p, slice(i, 5)) == get_number(p, slice(5, 9)):
                pandigital_products.append(get_number(p, slice(5, 9)))
                s += get_number(p, slice(5, 9))
    return s, pandigital_products
solve()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11318407960199005, 'fraction_numerical': 0.03980099502487562, 'mean_word_length': 3.690962099125364, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '51113', 'license': 'MIT', 'n_tokens_mistral': 579, 'n_tokens_neox': 514, 'n_words': 208, 'path': '26-50/p32.ipynb', 'repo_name': 'Sorosliu1029/Euler', 'size': '1608'}