From a64106f262d770335fccc51c201265c92c8a334d Mon Sep 17 00:00:00 2001 From: "flyingscorpio@pinebookpro" Date: Mon, 17 Jan 2022 12:45:09 +0100 Subject: [PATCH] Finish euclide algo --- algebre-non-lineaire/euclide_etendu.py | 37 +++++++++++++++++++------- 1 file changed, 27 insertions(+), 10 deletions(-) mode change 100644 => 100755 algebre-non-lineaire/euclide_etendu.py diff --git a/algebre-non-lineaire/euclide_etendu.py b/algebre-non-lineaire/euclide_etendu.py old mode 100644 new mode 100755 index a5f4dac..850cc18 --- a/algebre-non-lineaire/euclide_etendu.py +++ b/algebre-non-lineaire/euclide_etendu.py @@ -7,17 +7,34 @@ Calcule le PGCD de deux nombres et trouve les coefficients de Bezout. import sys -assert len(sys.argv) == 3 -a = int(sys.argv[1]) -b = int(sys.argv[2]) - -print("r u v q") +def main(): + assert len(sys.argv) == 3 + a = int(sys.argv[1]) + b = int(sys.argv[2]) # Initialisation -r = [a, b] -u = [1, 0] -v = [0, 1] -q = [False, a // b] + r = ["r", a, b] + u = ["u", 1, 0] + v = ["v", 0, 1] + q = ["q", "", a // b] # Séquence -r.append(r[-2] % r[-1]) + while True: + r.append(r[-2] % r[-1]) + u.append(u[-2] - (q[-1] * u[-1])) + v.append(v[-2] - (q[-1] * v[-1])) + if r[-1] == 0: + q.append("") + break + q.append(r[-2] // r[-1]) + + print_table(r, u, v, q) + +def print_table(r, u, v, q): + """Représentation de l'algorithme""" + for i in range(len(r)): + print(f"{r[i]:^5} {u[i]:^5} {v[i]:^5} {q[i]:^5}") + + +if __name__ == "__main__": + main()