Skip to content

Instantly share code, notes, and snippets.

@samrat
Created September 12, 2011 14:56
Show Gist options
  • Save samrat/1211472 to your computer and use it in GitHub Desktop.
Save samrat/1211472 to your computer and use it in GitHub Desktop.
Euclid's algorithm for finding greatest common divisor implemented in Python
def HCF(a,b):
''' Returns HCF(highest common factor) of a and b
http://en.wikipedia.org/wiki/Euclidean_algorithm
'''
great = max(a,b)
less = min(a,b)
great = great % less
if great == 0:
return less
return HCF(great, less)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment