def gcd(m,n):
m,n = sorted([m,n])
while m != 0:
m, n = (n % m), m
return n
Humorously, I resisted using a recursive algorithm. I don't know why, but it just seemed more reasonable to use a straight iterative one. Also I really like how m,n = (n%m), m saves us from having to declare a temporary variable.
No comments:
Post a Comment