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:
keshav Sharma 2022-07-24 21:33:10 +05:30 committed by GitHub
parent d53fdc29e2
commit 7d9ebee75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
>>> gcd(23, 42)
>>> greatest_common_divisor(23, 42)
1
>>> gcd(15, 33)
>>> greatest_common_divisor(15, 33)
3
>>> gcd(12345, 67890)
>>> greatest_common_divisor(12345, 67890)
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:
"""
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)
15
@ -49,7 +49,7 @@ def lcm(x: int, y: int) -> int:
192
"""
return (x * y) // gcd(x, y)
return (x * y) // greatest_common_divisor(x, y)
def solution(n: int = 20) -> int: