From c8216612630e29628f26c9914aa438dfa7677557 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Sat, 28 Sep 2024 14:37:08 -0300 Subject: [PATCH] Refactor problem --- solutions/project-euler/005/005.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/solutions/project-euler/005/005.py b/solutions/project-euler/005/005.py index 1ae42288..0ca95faa 100644 --- a/solutions/project-euler/005/005.py +++ b/solutions/project-euler/005/005.py @@ -1,3 +1,6 @@ +import functools + + def gcd(x, y): if y == 0: return x @@ -5,15 +8,7 @@ def gcd(x, y): def lcm(x, y): - return abs(x) / gcd(x, y) * abs(y) - - -def lcm_many(numbers): - result = numbers[0] - - for n in numbers[1:]: - result = lcm(result, n) - return result + return int(abs(x) / gcd(x, y) * abs(y)) -print(int(lcm_many(range(1, 21)))) +print(functools.reduce(lcm, range(1, 21)))