Project Euler #32: Pandigital products

  • + 0 comments
    from itertools import permutations
    
    def calculate_product(item):
        x = (len(item) // 2) + (len(item) % 2)
        return int(''.join(item[0:1])) * int(''.join(item[1:x]))
    
    def main():
        max_number = int(input("Enter the maximum number: "))
        number = [str(x) for x in range(1, max_number + 1)]
        p_numbers = permutations(number)
        unique_products = set()
    
        for item in p_numbers:
            product = calculate_product(item)
            if product == int(''.join(item[x:])) and len(item) > 1:
                unique_products.add(int(''.join(item[x:])))
    
        print(sum(unique_products))
    
    if __name__ == "__main__":
        main()