mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-20 13:39:48 +00:00
chore: rename gcd to greatest_common_divisor (#6265)
As described in CONTRIBUTING.md > Expand acronyms because gcd() is hard to understand but greatest_common_divisor() is not. Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
parent
d53fdc29e2
commit
7d9ebee75f
@ -16,28 +16,28 @@ References:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def gcd(x: int, y: int) -> int:
|
def greatest_common_divisor(x: int, y: int) -> int:
|
||||||
"""
|
"""
|
||||||
Euclidean GCD algorithm (Greatest Common Divisor)
|
Euclidean Greatest Common Divisor algorithm
|
||||||
|
|
||||||
>>> gcd(0, 0)
|
>>> greatest_common_divisor(0, 0)
|
||||||
0
|
0
|
||||||
>>> gcd(23, 42)
|
>>> greatest_common_divisor(23, 42)
|
||||||
1
|
1
|
||||||
>>> gcd(15, 33)
|
>>> greatest_common_divisor(15, 33)
|
||||||
3
|
3
|
||||||
>>> gcd(12345, 67890)
|
>>> greatest_common_divisor(12345, 67890)
|
||||||
15
|
15
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return x if y == 0 else gcd(y, x % y)
|
return x if y == 0 else greatest_common_divisor(y, x % y)
|
||||||
|
|
||||||
|
|
||||||
def lcm(x: int, y: int) -> int:
|
def lcm(x: int, y: int) -> int:
|
||||||
"""
|
"""
|
||||||
Least Common Multiple.
|
Least Common Multiple.
|
||||||
|
|
||||||
Using the property that lcm(a, b) * gcd(a, b) = a*b
|
Using the property that lcm(a, b) * greatest_common_divisor(a, b) = a*b
|
||||||
|
|
||||||
>>> lcm(3, 15)
|
>>> lcm(3, 15)
|
||||||
15
|
15
|
||||||
@ -49,7 +49,7 @@ def lcm(x: int, y: int) -> int:
|
|||||||
192
|
192
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return (x * y) // gcd(x, y)
|
return (x * y) // greatest_common_divisor(x, y)
|
||||||
|
|
||||||
|
|
||||||
def solution(n: int = 20) -> int:
|
def solution(n: int = 20) -> int:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user