-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem32.py
60 lines (38 loc) · 1.27 KB
/
problem32.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import time
import math
def calculate_time(func):
def inner1(*args, **kwargs):
begin = time.time()
returned_value = func(*args, **kwargs)
end = time.time()
print("Total time taken in : ", func.__name__, end - begin)
return returned_value
return inner1
def concatenating(m, n):
return int(str(m) + str(n))
def is_pandigital(n):
digital_set = {'1', '2', '3', '4', '5','6', '7', '8', '9'}
n_set = set()
n = str(n)
if len(n) != 9:
return False
for i in range(0, len(n)):
n_set |= {n[i]}
return len(digital_set - n_set) == 0
def is_product_pandigital(m, n):
product = m*n
temp = concatenating(m, n)
temp = concatenating(temp, product)
return is_pandigital(temp)
@calculate_time
def pandigital_products():
product_set = set()
sum32 = 0
for num in range(1000, 9999):
for i in range(2, int(math.sqrt(num))):
if num % i == 0 and is_product_pandigital (i, int(num/i)) and num not in product_set:
sum32 += num
product_set |= {num}
print("{} x {} = {}".format(i, int(num/i), num))
return sum32
print(pandigital_products())