Skip to content

Instantly share code, notes, and snippets.

@fengs
Created April 16, 2014 03:22
Show Gist options
  • Save fengs/10802718 to your computer and use it in GitHub Desktop.
Save fengs/10802718 to your computer and use it in GitHub Desktop.
>>> from fractions import gcd
>>> gcd(20,8)
4
>>> print inspect.getsource(gcd)
def gcd(a, b):
"""Calculate the Greatest Common Divisor of a and b.
Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
"""
while b:
a, b = b, a%b
return a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment