Skip to content
Snippets Groups Projects
Commit 610cb0bc authored by gawen.ackerman's avatar gawen.ackerman :robot:
Browse files

multiply

parent b4deb14e
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,8 @@ import json
def unicode_superscripts(value):
exponent_dict = {"0": "", "1": "¹", "2": "²", "3": "³", "4": "", "5": "", "6": "", "7": "", "8": "", "9": ""}
exponent_dict = {"0": "", "1": "¹", "2": "²", "3": "³",
"4": "", "5": "", "6": "", "7": "", "8": "", "9": ""}
return ("" if value < 0 else "") + "".join(exponent_dict[x] for x in str(abs(value)))
......@@ -24,23 +25,33 @@ class Polynomial:
a_count = len(a)
b_count = len(b)
if a_count > b_count:
diff = b_count-a_count
diff = a_count-b_count
for x in range(diff):
b.append(0)
else:
diff = a_count-b_count
diff = b_count-a_count
for x in range(diff):
a.append(0)
c = [0] * a_count
c = [0] * len(a)
for x in range(len(a)):
c[x] = a[x]+b[x]
return Polynomial(tuple(c))
def __mul__(self, other):
pass
a = list(self.value)
b = list(other.value)
a_count = len(a)
b_count = len(b)
size = ((a_count - 1) + (b_count - 1) + 1)
c = [0] * size
for i in range(a_count):
for j in range(b_count):
c[i+j] += a[i]*b[j]
return Polynomial(tuple(c))
def __mod__(self, other):
pass
......@@ -72,13 +83,22 @@ def reed_solomon(points, data_length, last_error_index, prime_number):
def main():
p1 = Polynomial((5, 1, 4))
p2 = Polynomial((5, 2, 3, 4))
p3 = p1*p2
print(p1)
print(p2)
print(p3)
with open("messages.json") as f:
messages = json.load(f)
print(len(messages))
for message in messages:
points = [(x, y) for x, y in enumerate(message["points"])]
corrected_data = reed_solomon(points, message["data_length"], message["last_error_index"], message["prime_number"])
corrected_data = reed_solomon(
points, message["data_length"], message["last_error_index"], message["prime_number"])
print(corrected_data)
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment