From 41260c43c31aa5e5f267e91df74e32c47bdaabb4 Mon Sep 17 00:00:00 2001 From: ACKERMANNGUE <gawen.ackermann@etu.hesge.ch> Date: Tue, 7 Dec 2021 10:39:19 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9alisation=20bachet-b=C3=A9zout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- polynomial.py | 52 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/polynomial.py b/polynomial.py index ef82cc0..29d458e 100644 --- a/polynomial.py +++ b/polynomial.py @@ -1,6 +1,7 @@ from numbers import Number import itertools import json +from typing import Tuple def unicode_superscripts(value): @@ -61,11 +62,11 @@ class Polynomial: result[i] = a[i] % other for i in reversed(range(len(result))): - if result[i] ==0: + if result[i] == 0: del result[i] else: break - + return Polynomial(tuple(result)) def __str__(self): @@ -86,6 +87,36 @@ class Polynomial: return str_value +def compute_bachet_bezout(a, b): + r = [] + x = [] + y = [] + q = [] + + # Init + r.append(a) + x.append(1) + y.append(0) + q.append(0) + + r.append(b) + x.append(0) + y.append(1) + q.append(0) + + # Computing + i = 1 + while r[i] > 0: + i += 1 + r.append(r[i-2] % r[i-1]) + q.append(int(r[i-2] / r[i-1])) + if r[i] > 0: + x.append(x[i-2]-q[i]*x[i-1]) + y.append(y[i-2]-q[i]*y[i-1]) + + return x[-1], y[-1] + + def compute_lagrange_polynomial(points, prime_number): pass @@ -99,11 +130,16 @@ def main(): p1 = Polynomial((5, 1, 4)) p2 = Polynomial((5, 2, 3, 4)) p3 = p1*p2 - print(p1) - print(p2) - print(p3) - print(p3%4) - print(p3%5) + # print(p1) + # print(p2) + # print(p3) + # print(p3 % 4) + # print(p3 % 5) + a = 168 + b = 68 + x, y = compute_bachet_bezout(a, b) + print("Pour les chiffres " + str(a) + " et " + str(b) + + ". Les coéfficients de Bachet-Bézout sont : " + str(x) + " et " + str(y)) with open("messages.json") as f: messages = json.load(f) @@ -118,4 +154,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() -- GitLab