return two 4-digit number whose difference is equal to the difference of their digits' product in python

Here's a function that takes no arguments and returns two 4-digit numbers whose difference is equal to the difference of their digits' product.

main.py
import math

def digits_product(num):
    digits = [int(d) for d in str(num)]
    product = math.prod(digits)
    return product

def find_numbers():
    for num1 in range(1000, 10000):
        for num2 in range(num1+1, 10000):
            if abs(num1 - num2) == abs(digits_product(num1) - digits_product(num2)):
                return num1, num2
347 chars
13 lines

The function digits_product takes an integer as input and returns the product of its digits. The find_numbers function then loops through all pairs of 4-digit numbers, checks if their difference is equal to the difference of their digits' product, and returns the pair of numbers if found. Note that we start the inner loop at num1+1 to avoid considering pairs of identical numbers.

gistlibby LogSnag