Created
July 28, 2014 20:35
-
-
Save darian929/2710c79a0f582584e2e8 to your computer and use it in GitHub Desktop.
greatest common divisor using recursion 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 gcdRecur(a, b): | |
''' | |
a, b: positive integers | |
returns: a positive integer, the greatest common divisor of a & b. | |
''' | |
# Your code here | |
low = min(a,b) | |
high = max(a, b) | |
if high%low == 0: | |
return low | |
remainder = high%low | |
return gcdRecur(low, remainder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment