Take the number 192 and multiply it by each of 1, 2, and 3:

  • 192 × 1 = 192
  • 192 × 2 = 384
  • 192 × 3 = 576

By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)

The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).

What is 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?

Awaiting feedback.

def check_pandigital(n):
    """Assumes n is a string of numbers.
    returns True if 1-9 in number, False otherwise."""
    for i in range(1, 9):
        if str(i) not in n:
            return False
    return True

def multiply_concatenate(n):
    """Assumes n is a positive integer.
    returns concatenations of number multiplied by a range if (1-9) in number."""
    s = str(n)
    for i in range(2, 10):
        s += str(i * n)
        if check_pandigital(s):
            return s

def check_range(n):
    """Assumes n is a range(integer).
    generates pandigitals within the range."""
    for i in range(2, n):
        mult_conc = multiply_concatenate(i)
        if mult_conc and len(mult_conc) <= 9:
            yield mult_conc

if __name__ == '__main__':
    print(max(int(number) for number in check_range(10000)))
  • 2
    \$\begingroup\$ Why'd you add the rant to seven of your recent questions? It is counterproductive. \$\endgroup\$ – 1201ProgramAlarm Jul 22 at 4:41
  • \$\begingroup\$ I'm sorry if you're offended or anything but I'm making some effort to learn and become better at programming all I'm getting since the beginning of the day are downvotes without feedback so I'm a bit confused why i'm getting the downvotes though all the codes I posted are working maybe not the most efficient but get you the right answer. \$\endgroup\$ – user203258 Jul 22 at 4:46
  • 1
    \$\begingroup\$ I'm not offended. But I'd be less inclined to review the code with that paragraph in it (I don't know Python so I'm not going to review it). You've asked several questions within a short time span, and questions on CR can take several days to get answered. You can improve the questions by including a link to the challenge question, a summary of the question, and an explanation of your code. See How to Ask. Perhaps check out a related question. \$\endgroup\$ – 1201ProgramAlarm Jul 22 at 5:00
  • \$\begingroup\$ Also see this answer to a recent question on Meta. \$\endgroup\$ – 1201ProgramAlarm Jul 22 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy