Created
September 12, 2011 14:56
-
-
Save samrat/1211472 to your computer and use it in GitHub Desktop.
Euclid's algorithm for finding greatest common divisor implemented in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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