Skip to content

Instantly share code, notes, and snippets.

@waylon531
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waylon531/9027315 to your computer and use it in GitHub Desktop.
Save waylon531/9027315 to your computer and use it in GitHub Desktop.
Greatest common divisor using the Euclidian Algorithm
import sys,math
a = float(sys.argv[1])
b = float(sys.argv[2])
remainder = 1.0
if a<b:
a=b
b=float(sys.argv[1])
c = a/b
while(round(remainder,2)!=0):
q=math.floor(c+.000001)
remainder=c-q
a=b
b=remainder*b
if b!=0:
c=a/b
#print c,a,b,q,remainder
print int(round(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment