Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions gcd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Wrong gcd find 5 mistakes
# Wrong gcd find 5 mistakes <- maybe this is fifth 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(10, 0))
print(gcd(123, 3))
print(gcd(1000000, 64))
print(gcd(0, 0))

# Examples

# gcd(10, 0) => 10
# gcd(123, 3) => 3
Expand Down