Rozwiązanie zadania "Ilorazy pierścienia wielomianów" #35
69
main.py
69
main.py
@ -9,6 +9,8 @@ class Poly:
|
|||||||
self.elements = {}
|
self.elements = {}
|
||||||
self.int_mod = int_mod
|
self.int_mod = int_mod
|
||||||
|
|
||||||
|
elements = [x % self.int_mod for x in elements]
|
||||||
|
|
||||||
elements = list(reversed(elements))
|
elements = list(reversed(elements))
|
||||||
z = 0
|
z = 0
|
||||||
for i in elements:
|
for i in elements:
|
||||||
@ -19,7 +21,7 @@ class Poly:
|
|||||||
|
|
||||||
i = len(elements) - 1
|
i = len(elements) - 1
|
||||||
for e in elements:
|
for e in elements:
|
||||||
self.elements[f"x{i}"] = e % self.int_mod
|
self.elements[f"x{i}"] = e
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -69,7 +71,7 @@ class Poly:
|
|||||||
for i in range(power - 1):
|
for i in range(power - 1):
|
||||||
poly *= poly
|
poly *= poly
|
||||||
|
|
||||||
return poly
|
return Poly(poly.int_mod, list(reversed(list(poly.elements.values()))))
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
|
||||||
@ -179,13 +181,13 @@ class Poly:
|
|||||||
mulpoly = divpoly * other
|
mulpoly = divpoly * other
|
||||||
|
|
||||||
poly -= mulpoly
|
poly -= mulpoly
|
||||||
# print(poly)
|
|
||||||
for i in poly.elements.keys():
|
for i in poly.elements.keys():
|
||||||
if poly.elements[f"{i}"] != 0:
|
if poly.elements[f"{i}"] != 0:
|
||||||
fdeg = int(i[1:])
|
fdeg = int(i[1:])
|
||||||
break
|
break
|
||||||
|
|
||||||
return poly
|
return Poly(poly.int_mod, list(reversed(list(poly.elements.values()))))
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -238,8 +240,9 @@ class PolyIntField:
|
|||||||
def __init__(self, int_mod, poly_mod):
|
def __init__(self, int_mod, poly_mod):
|
||||||
self.int_modulo = int_mod
|
self.int_modulo = int_mod
|
||||||
self.poly_modulo = Poly(int_mod, poly_mod)
|
self.poly_modulo = Poly(int_mod, poly_mod)
|
||||||
product = list(itertools.product([x for x in range(0, int_mod)],
|
product = list(itertools.product(
|
||||||
repeat=len(poly_mod) - 1))
|
[x for x in range(0, self.int_modulo)],
|
||||||
|
repeat=len(self.poly_modulo.elements) - 1))
|
||||||
|
|
||||||
self.elements = []
|
self.elements = []
|
||||||
for p in product:
|
for p in product:
|
||||||
@ -312,51 +315,13 @@ class PolyIntField:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
# if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
# print("Niepoprawny input")
|
print("Niepoprawny input")
|
||||||
# exit(1)
|
exit(1)
|
||||||
#
|
|
||||||
# if sys.argv[1].find(",") != -1:
|
|
||||||
# print(f"Proszę użyć spacji, nie przecinków: '{sys.argv[1]}'")
|
|
||||||
# exit(1)
|
|
||||||
|
|
||||||
|
if sys.argv[1].find(",") != -1:
|
||||||
|
print(f"Proszę użyć spacji, nie przecinków: '{sys.argv[1]}'")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# field = PolyIntField(int(sys.argv[1]), ast.literal_eval(sys.argv[2]))
|
field = PolyIntField(int(sys.argv[1]), ast.literal_eval(sys.argv[2]))
|
||||||
# c = Poly(2, [0, 0, 0, 1])
|
print(field)
|
||||||
# # print(c)
|
|
||||||
# a = Poly(2, [1, 0, 0, 1])
|
|
||||||
# print(a == c)
|
|
||||||
# print(c == a)
|
|
||||||
# print(a + Poly(2, [1]) == c)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
f = PolyIntField(2, [1, 1, 1])
|
|
||||||
print(f)
|
|
||||||
|
|
||||||
field = PolyIntField(3, [1, 1, 2, 2])
|
|
||||||
print(field)
|
|
||||||
|
|
||||||
# g = PolyIntField(3, [1, 2, 3])
|
|
||||||
# print(g)
|
|
||||||
|
|
||||||
|
|
||||||
# a = Poly(5, [1, 0, 0])
|
|
||||||
# b = Poly(5, [1])
|
|
||||||
# print(a == b)
|
|
||||||
# print(b == a)
|
|
||||||
# a = Poly(5, [1, 3])
|
|
||||||
# b = Poly(5, [1, 2])
|
|
||||||
# print(a + b)
|
|
||||||
#
|
|
||||||
# c = Poly(4, [2, 0, 3, 2])
|
|
||||||
# d = Poly(4, [2, 0, 1, 2])
|
|
||||||
# print(c)
|
|
||||||
# print(d)
|
|
||||||
# # 0x^5 + 3x^4 + 0x^3 + 0x^2 + 0x^1 + 0
|
|
||||||
# print(c * d)
|
|
||||||
# print(Poly(5, [1, 1]) == Poly(5, [1]))
|
|
||||||
# print(Poly(5, [1]) == Poly(5, [1]))
|
|
||||||
|
|
||||||
# [[0], [1, 1], [2, 1], [1, 2], [2, 2], [2, 0, 1], [0, 1, 1], [1, 1, 1], [0, 2, 1], [1, 2, 1], [1, 0, 2], [0, 1, 2], [2, 1, 2], [0, 2, 2], [2, 2, 2]],
|
|
||||||
# [[0], [0, 1, 1], [0, 1, 2], [0, 2, 1], [0, 2, 2], [1, 0, 2], [1, 1], [1, 1, 1], [1, 2], [1, 2, 1], [2, 0, 1], [2, 1], [2, 1, 2], [2, 2], [2, 2, 2]],
|
|
Loading…
Reference in New Issue
Block a user