Skip to content

Commit

Permalink
Refactor problem
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Sep 28, 2024
1 parent cf9f1f9 commit c821661
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions solutions/project-euler/005/005.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import functools


def gcd(x, y):
if y == 0:
return x
return gcd(y, 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)))

0 comments on commit c821661

Please sign in to comment.