Created
September 1, 2022 13:21
-
-
Save jeremy9959/50d6a4faffb479de67a917df649a190b to your computer and use it in GitHub Desktop.
Math 5210 Euclidean Algorithm
This file contains 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 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