Skip to content

Instantly share code, notes, and snippets.

@raheemazeezabiodun
Created July 23, 2019 12:04
Show Gist options
  • Save raheemazeezabiodun/cf6be89f5b59c1670ecadf28f64634a6 to your computer and use it in GitHub Desktop.
Save raheemazeezabiodun/cf6be89f5b59c1670ecadf28f64634a6 to your computer and use it in GitHub Desktop.
Computing greatest common divisor
def slow_gcd(arg1,arg2):
gcd = 0
for num in range(1, arg1 + arg2+ 1):
if (arg1 % num == 0) and (arg2 %num == 0):
gcd = num
return gcd
def fast_gcd(arg1,arg2):
if arg2 == 0:
return arg1
arg1_prime = arg1 % arg2
return fast_gcd(arg2, arg1_prime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment