From d770dd831eb74948d845cf9f474dc2c6034590f0 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 12 Oct 2020 21:49:31 +0200 Subject: [PATCH] Complete problem --- src/task32 - Pandigital products.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/task32 - Pandigital products.py b/src/task32 - Pandigital products.py index 139d88d..e651f97 100644 --- a/src/task32 - Pandigital products.py +++ b/src/task32 - Pandigital products.py @@ -1,16 +1,14 @@ -totalSum=0 -usedFactors = [] -for i in range(1, 10000): - if i%100==0: - print(str(i/100) + "%") - for j in range(1, 10000): - x=i*j - if len(str(i))+len(str(j))+len(str(x))==9: - result = sum([int(k) for k in str(x)]) - result += sum([int(k) for k in str(i)]) - result += sum([int(k) for k in str(j)]) - if sum==1+2+3+4+5+6+7+8+9: - totalSum+=x +from itertools import permutations +from math import ceil -print(totalSum) -#HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum. \ No newline at end of file +def isPanDigital(i,j,x): + return sorted(str(i) + str(j) + str(x)) == ['1' ,'2', '3', '4', '5', '6', '7', '8', '9'] + +panDigits = [] +for i in range(1,10000): + for j in range(1,ceil(10000/i)): + prod = i*j + if isPanDigital(i, j, prod) and not prod in panDigits: + panDigits.append(prod) + +print(sum(panDigits)) \ No newline at end of file