def slow_gcd(x,y):
""" greatest common divisor of two integers - naive inefficient method """
assert isinstance(x,int) and isinstance(y,int) # type checking: x and y both integers
x,y = abs(x),abs(y) # simultaneous assignment to x and y
# gcd invariant to abs. Both x,y now non-negative
if x0:
x,y = y,x%y
return x
def display_gcd(x,y):
""" greatest common divisor of two integers - Euclid's algorithm
Function prints all intermediate results along the way """
assert isinstance(x,int) and isinstance(y,int) # type checking: x and y both integers
x,y = abs(x),abs(y) # simultaneous assignment to x and y
# gcd invariant to abs. Both x,y now non-negative
if x0:
x,y = y,x%y
print(x,y)
return x