Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Greatest Common Divisor by Kurush
def gcd(a, b):
if a == 0: return b
elif b == 0: return a
elif a == b: return a
elif a > b: return gcd(a % b, b)
elif b > a: return gcd(b % a, a)
def greatest_common_divisor(*args:int) -> int:
for i, arg in enumerate(args):
if i == 0: value = arg
else: value = gcd(value, arg)
return value
if __name__ == '__main__':
print("Example:")
print(greatest_common_divisor(6, 4))
# These "asserts" are used for self-checking and not for an auto-testing
assert greatest_common_divisor(6, 4) == 2
assert greatest_common_divisor(2, 4, 8) == 2
assert greatest_common_divisor(2, 3, 5, 7, 11) == 1
assert greatest_common_divisor(3, 9, 3, 9) == 3
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 12, 2021
Comments: