From 734262911928152abce5584983c2656a7d91fde9 Mon Sep 17 00:00:00 2001 From: Djokzer <abivarmank@gmail.com> Date: Thu, 9 Dec 2021 15:16:51 +0100 Subject: [PATCH] Still don't work --- reed_solomon.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/reed_solomon.py b/reed_solomon.py index 870d394..698cc4a 100644 --- a/reed_solomon.py +++ b/reed_solomon.py @@ -1,23 +1,32 @@ # Created on 09/12/2021 from polynome import * +from inverse_mult import * def get_possibilities(l: list): pass def lagrange_compute(l: list) -> polynome: list_s = [0] * len(l) - list_p = [1] * 2 + [0] * (len(l)-2) + list_p = [0] * len(l) sum_poly = polynome(list_s) - product_poly = polynome(list_p) + #product_poly = polynome(list_p) + first_time = True for x_i, y_i in enumerate(l): for x_j, y_j in enumerate(l): if x_j != x_i: - product_poly = product_poly.mul(polynome([(y_i * (0-x_j)) /(x_i - x_j) , y_i / (x_i - x_j)])) - #product_poly.show() + list_p[0] = -x_j / (x_i - x_j) + list_p[1] = 1 / (x_i - x_j) + if first_time: + product_poly = polynome(list_p) + first_time = False + else: + product_poly = product_poly.mul(polynome(list_p)) + product_poly.show() + first_time = True sum_poly = sum_poly.add(product_poly) - #sum_poly.show() - product_poly = polynome(list_p) + sum_poly.show() + list_p = [0] * len(l) return sum_poly def check_nb_error(l: list, p: polynome) -> int: @@ -25,7 +34,7 @@ def check_nb_error(l: list, p: polynome) -> int: if __name__ == '__main__': list_ = [1, 2, 3] - print(list_) + #print(list_) poly = lagrange_compute(list_) poly.show() #print(poly.evaluate(0)) \ No newline at end of file -- GitLab