Skip to content
Snippets Groups Projects
Commit b36e00f4 authored by quentin.fasler's avatar quentin.fasler
Browse files
parents 8043d7b2 41260c43
No related branches found
No related tags found
No related merge requests found
from numbers import Number from numbers import Number
import itertools import itertools
import json import json
from typing import Tuple
def unicode_superscripts(value): def unicode_superscripts(value):
...@@ -90,6 +91,36 @@ class Polynomial: ...@@ -90,6 +91,36 @@ class Polynomial:
return str_value 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): def compute_lagrange_polynomial(points, prime_number):
pass pass
...@@ -103,11 +134,16 @@ def main(): ...@@ -103,11 +134,16 @@ def main():
p1 = Polynomial((5, 1, 4)) p1 = Polynomial((5, 1, 4))
p2 = Polynomial((5, 2, 3, 4)) p2 = Polynomial((5, 2, 3, 4))
p3 = p1*p2 p3 = p1*p2
print(p1) # print(p1)
print(p2) # print(p2)
print(p3) # print(p3)
print(p3%4) # print(p3 % 4)
print(p3%5) # 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: with open("messages.json") as f:
messages = json.load(f) messages = json.load(f)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment