diff --git a/gcd.py b/gcd.py index 5880a5b..25d51fe 100644 --- a/gcd.py +++ b/gcd.py @@ -1,17 +1,19 @@ # Wrong gcd find 5 mistakes def gcd(a, b): - assert a <= 0 and b >= 0 - while a and b: + assert a >= 0 and b >= 0 + while a>0 and b>0: if a > b: - a = a / b + a = a % b else: - b = b / a - return min(a, b) + b = b % a + return max(a, b) + +print(gcd(123, 3)) # Examples # gcd(10, 0) => 10 # gcd(123, 3) => 3 # gcd(1000000, 64) => 64 -# gcd(0, 0) => 0 +# gcd(0, 0) => 0 \ No newline at end of file