Skip to content

Instantly share code, notes, and snippets.

@jeremy9959
Created September 1, 2022 13:21
Show Gist options
  • Save jeremy9959/50d6a4faffb479de67a917df649a190b to your computer and use it in GitHub Desktop.
Save jeremy9959/50d6a4faffb479de67a917df649a190b to your computer and use it in GitHub Desktop.
Math 5210 Euclidean Algorithm
def euclid(a,b):
x0,x1=1,0
y0,y1=0,1
r0,r1=a,b
q=""
format_string="{:>14} {:>14} {:>14} {:>14}"
print(format_string.format("",a,x0,y0))
while r1>0:
print(format_string.format(q,r1,x1,y1))
q=r0//r1
r=r0-q*r1
x=x0-q*x1
y=y0-q*y1
x0,x1=x1,x
y0,y1=y1,y
r0,r1=r1,r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment