From 038458f2aaa535c498dd2d2aba7beca3acd03b4d Mon Sep 17 00:00:00 2001 From: romatsp Date: Fri, 28 Sep 2018 00:43:54 +0300 Subject: [PATCH 1/3] fix gcd --- gcd.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gcd.py b/gcd.py index 5880a5b..9556139 100644 --- a/gcd.py +++ b/gcd.py @@ -1,13 +1,13 @@ # Wrong gcd find 5 mistakes -def gcd(a, b): - assert a <= 0 and b >= 0 +def gcd(a: int, b: int): #1 + assert a < 0 and b > 0 #2 while a and b: if a > b: - a = a / b + a = a % b #3 else: - b = b / a - return min(a, b) + b = b % a #4 + return max(a, b) #5 # Examples From b3c331a6a32c2a7ce6e952a2d6ee7c4d7930152f Mon Sep 17 00:00:00 2001 From: romatsp Date: Fri, 28 Sep 2018 23:19:40 +0300 Subject: [PATCH 2/3] So of course, my mistake. For some reason, I thought that the assert is an output, not a condition (assert , ). I did a lot of checks, but did not expect a<0. I will be more attentive. (From the words of Google Translator - it's recorded correctly, I hope :) --- gcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcd.py b/gcd.py index 9556139..4cc85e8 100644 --- a/gcd.py +++ b/gcd.py @@ -1,7 +1,7 @@ # Wrong gcd find 5 mistakes def gcd(a: int, b: int): #1 - assert a < 0 and b > 0 #2 + assert, a > 0 and b > 0 #2 while a and b: if a > b: a = a % b #3 From 550d159a9a797b414b80836a00e0a27c2012cfb9 Mon Sep 17 00:00:00 2001 From: romatsp Date: Sat, 29 Sep 2018 15:07:34 +0300 Subject: [PATCH 3/3] :( deleted comma from assert --- gcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcd.py b/gcd.py index 4cc85e8..cf4bcaa 100644 --- a/gcd.py +++ b/gcd.py @@ -1,7 +1,7 @@ # Wrong gcd find 5 mistakes def gcd(a: int, b: int): #1 - assert, a > 0 and b > 0 #2 + assert a > 0 and b > 0 #2 while a and b: if a > b: a = a % b #3