24 lines
558 B
Python
24 lines
558 B
Python
from lib_misc import permutations
|
|
|
|
|
|
def is_solution(s):
|
|
a, b, c = int(s[0:2]), int(s[2:5]), int(s[5:])
|
|
if a * b == c:
|
|
return c
|
|
a, b, c = int(s[0:1]), int(s[1:5]), int(s[5:])
|
|
if a * b == c:
|
|
return c
|
|
return 0
|
|
|
|
|
|
def euler_032():
|
|
return sum(set([is_solution("".join(p))
|
|
for p in permutations("123456789")]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
assert(is_solution("391867254") == 7254)
|
|
assert(is_solution("391867245") == 0)
|
|
print("e032.py: {}".format(euler_032()))
|
|
assert(euler_032() == 45228)
|