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)))