Skip to content
Snippets Groups Projects
Commit 66a3bb06 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Changed indentation to tabs, modified get_possibilities

parent fcdf70e8
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,10 @@ from euclide import * ...@@ -7,10 +7,10 @@ from euclide import *
# x = Multiplicative inverse of a mod p: # x = Multiplicative inverse of a mod p:
# a * x mod p = 1 # a * x mod p = 1
def inverse_mult(a, p) : def inverse_mult(a, p) :
pgcd, x, y = pgcd_etendu(a, p) pgcd, x, y = pgcd_etendu(a, p)
if pgcd != 1: if pgcd != 1:
return None return None
return x if a > p else y return x if a > p else y
if __name__ == "__main__": if __name__ == "__main__":
print(inverse_mult(3, 11)) print(inverse_mult(3, 11))
\ No newline at end of file \ No newline at end of file
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
from polynome import * from polynome import *
if __name__ == "__main__": if __name__ == "__main__":
pol1 = polynome([1, 2, 3, 4, 5]) pol1 = polynome([1, 2, 3, 4, 5])
pol2 = polynome([2, 3, 4, 4, 4]) pol2 = polynome([2, 3, 4, 4, 4])
# pol3 = pol1.add(pol2) # pol3 = pol1.add(pol2)
pol1.show() pol1.show()
pol1.evaluate(2) pol1.evaluate(2)
\ No newline at end of file \ No newline at end of file
...@@ -4,46 +4,46 @@ ...@@ -4,46 +4,46 @@
import math import math
class polynome(): class polynome():
def __init__(self, coefs : list): def __init__(self, coefs : list):
self.coefs = coefs self.coefs = coefs
self.prime_mod = 229 self.prime_mod = 229
def show(self): def show(self):
for i in range(len(self.coefs) - 1, -1, -1): for i in range(len(self.coefs) - 1, -1, -1):
power = "" power = ""
if self.coefs[i] != 0: if self.coefs[i] != 0:
coef = str(self.coefs[i]) coef = str(self.coefs[i])
if i != 0: # its not 0's degree if i != 0: # its not 0's degree
power = f"x^{i} + " power = f"x^{i} + "
else: else:
coef = "" coef = ""
print(f"{coef}{power}", end="") print(f"{coef}{power}", end="")
print() # new line print() # new line
def add(self, poly_2): def add(self, poly_2):
coeff_poly_1 = self.coefs coeff_poly_1 = self.coefs
if len(coeff_poly_1) > len(poly_2.coefs): if len(coeff_poly_1) > len(poly_2.coefs):
while len(coeff_poly_1) > len(poly_2.coefs): while len(coeff_poly_1) > len(poly_2.coefs):
poly_2.coefs.append(0) poly_2.coefs.append(0)
else: else:
while len(coeff_poly_1) < len(poly_2.coefs): while len(coeff_poly_1) < len(poly_2.coefs):
coeff_poly_1.append(0) coeff_poly_1.append(0)
for i in range(0, len(coeff_poly_1)): for i in range(0, len(coeff_poly_1)):
coeff_poly_1[i] = (coeff_poly_1[i] + poly_2.coefs[i]) % self.prime_mod coeff_poly_1[i] = (coeff_poly_1[i] + poly_2.coefs[i]) % self.prime_mod
return polynome(coeff_poly_1) return polynome(coeff_poly_1)
def mul(self, poly_2): def mul(self, poly_2):
coeff_poly_res = [0] * (len(self.coefs) + len(poly_2.coefs) - 1) coeff_poly_res = [0] * (len(self.coefs) + len(poly_2.coefs) - 1)
for index_1, value_1 in enumerate(self.coefs): for index_1, value_1 in enumerate(self.coefs):
for index_2, value_2 in enumerate(poly_2.coefs): for index_2, value_2 in enumerate(poly_2.coefs):
coeff_poly_res[index_1 + index_2] += (value_1 * value_2) % self.prime_mod coeff_poly_res[index_1 + index_2] += (value_1 * value_2) % self.prime_mod
return polynome(coeff_poly_res) return polynome(coeff_poly_res)
def evaluate(self, x): def evaluate(self, x):
# Using horner method # Using horner method
res = 0 res = 0
for i in range(len(self.coefs) - 1, -1, -1): for i in range(len(self.coefs) - 1, -1, -1):
res = (res * x + self.coefs[i]) res = (res * x + self.coefs[i])
return (res % self.prime_mod) return (res % self.prime_mod)
...@@ -3,7 +3,7 @@ from polynome import * ...@@ -3,7 +3,7 @@ from polynome import *
from inverse_mult import * from inverse_mult import *
from itertools import combinations from itertools import combinations
def get_possibilities(l: list): def get_possibilities(l: list, index: int):
# Transforme the list in list of tupples with their indexes # Transforme the list in list of tupples with their indexes
for x, _ in enumerate(l): for x, _ in enumerate(l):
...@@ -11,8 +11,8 @@ def get_possibilities(l: list): ...@@ -11,8 +11,8 @@ def get_possibilities(l: list):
# ! la valeur 20 est hardcodée. Paramètre de fonction ?? # ! la valeur 20 est hardcodée. Paramètre de fonction ??
l_fixe = l[20:] # Liste contenant aucune erreur l_fixe = l[index:] # Liste contenant aucune erreur
l_posi = l[:20] # Liste contenant des erreurs, l_posi = l[:index] # Liste contenant des erreurs,
p = list(combinations(l_posi, 2)) p = list(combinations(l_posi, 2))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment