Skip to content

Instantly share code, notes, and snippets.

@darian929
Created July 28, 2014 20:35
Show Gist options
  • Save darian929/2710c79a0f582584e2e8 to your computer and use it in GitHub Desktop.
Save darian929/2710c79a0f582584e2e8 to your computer and use it in GitHub Desktop.
greatest common divisor using recursion in python
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