From 268681aa37ab8f048e6f595608578f1154fe2416 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 14 Jan 2021 12:45:32 +0100 Subject: problem 38 in python --- python/038-pandigital_multiples.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/038-pandigital_multiples.py b/python/038-pandigital_multiples.py index be8fedc..33c7592 100644 --- a/python/038-pandigital_multiples.py +++ b/python/038-pandigital_multiples.py @@ -1,7 +1,7 @@ # ### # Pandigital multiples # Problem 38 -# +# # Take the number 192 and multiply it by each of 1, 2, and 3: # 192 × 1 = 192 # 192 × 2 = 384 @@ -12,7 +12,26 @@ # ### -def concatenated_prod(n): - cprod = "" - +import itertools + + +def is_palindrom(s): + return len(s) == 9 and ''.join(sorted(s)) == '123456789' + + +largest = 0 + +for n in range(1, 987654321): + results = [] + for mul in itertools.count(1): + results.append(n * mul) + str_res = ''.join([str(x) for x in results]) + res = int(str_res) + if is_palindrom(str_res) and res > largest: + largest = res + print(largest) + if res > 987654321: + break + +print(largest) -- cgit