From 92c027f44a0ffe5037a9f2972ef7cc3aac41129f Mon Sep 17 00:00:00 2001
From: body773
Date: Wed, 17 Oct 2018 09:56:20 +0300
Subject: [PATCH] fixing bugs on gcd.py
---
gcd.py | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/gcd.py b/gcd.py
index 5880a5b..3192995 100644
--- a/gcd.py
+++ b/gcd.py
@@ -1,17 +1,26 @@
# Wrong gcd find 5 mistakes
def gcd(a, b):
- assert a <= 0 and b >= 0
+ assert a >= 0 and b >= 0
while a and b:
if a > b:
- a = a / b
+ if a % b == 0:
+ return b
+ else:
+ a = a % b
else:
- b = b / a
- return min(a, b)
+ if b % a == 0:
+ return a
+ else:
+ b = b % a
+ return a + b
+print ('result: ',gcd(10, 0))
+print ('result: ',gcd(123, 3))
+print ('result: ',gcd(10000000, 64))
+print ('result: ',gcd(0, 0))
# Examples
-
-# gcd(10, 0) => 10
-# gcd(123, 3) => 3
-# gcd(1000000, 64) => 64
-# gcd(0, 0) => 0
+#gcd(10, 0) #=> 10
+#gcd(123, 3) #=> 3
+#gcd(1000000, 64) #=> 64
+#gcd(0, 0) #=> 0