From 0a79bc2d2bea94747e474fe26227b486057e087c Mon Sep 17 00:00:00 2001 From: Avyakth Challa Date: Tue, 18 Aug 2020 18:26:39 +0530 Subject: [PATCH 1/3] Added static type checking to linear_algebra/src/polynom-for-points.py --- linear_algebra/src/polynom-for-points.py | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/linear_algebra/src/polynom-for-points.py b/linear_algebra/src/polynom-for-points.py index dc0c3d95102e..adff1c4d9e35 100644 --- a/linear_algebra/src/polynom-for-points.py +++ b/linear_algebra/src/polynom-for-points.py @@ -1,4 +1,6 @@ -def points_to_polynomial(coordinates): +from typing import List, Union + +def points_to_polynomial(coordinates: List[List[int]]) -> str: """ coordinates is a two dimensional matrix: [[x, y], [x, y], ...] number of points you want to use @@ -25,15 +27,15 @@ def points_to_polynomial(coordinates): f(x)=x^2*5.0+x^1*-18.0+x^0*18.0 """ try: - check = 1 - more_check = 0 - d = coordinates[0][0] + check: int = 1 + more_check: int = 0 + d: int = coordinates[0][0] for j in range(len(coordinates)): if j == 0: continue if d == coordinates[j][0]: more_check += 1 - solved = "x=" + str(coordinates[j][0]) + solved: str = "x=" + str(coordinates[j][0]) if more_check == len(coordinates) - 1: check = 2 break @@ -48,16 +50,16 @@ def points_to_polynomial(coordinates): except Exception: check = 3 - x = len(coordinates) + x: int = len(coordinates) if check == 1: - count_of_line = 0 - matrix = [] + count_of_line: int = 0 + matrix: List[List]= [] # put the x and x to the power values in a matrix while count_of_line < x: - count_in_line = 0 - a = coordinates[count_of_line][0] - count_line = [] + count_in_line: int = 0 + a: int = coordinates[count_of_line][0] + count_line: List[int] = [] while count_in_line < x: count_line.append(a ** (x - (count_in_line + 1))) count_in_line += 1 @@ -66,21 +68,21 @@ def points_to_polynomial(coordinates): count_of_line = 0 # put the y values into a vector - vector = [] + vector: List[int] = [] while count_of_line < x: vector.append(coordinates[count_of_line][1]) count_of_line += 1 - count = 0 + count: int = 0 while count < x: - zahlen = 0 + zahlen: int = 0 while zahlen < x: if count == zahlen: zahlen += 1 if zahlen == x: break - bruch = (matrix[zahlen][count]) / (matrix[count][count]) + bruch: int = (matrix[zahlen][count]) / (matrix[count][count]) for counting_columns, item in enumerate(matrix[count]): # manipulating all the values in the matrix matrix[zahlen][counting_columns] -= item * bruch @@ -91,7 +93,7 @@ def points_to_polynomial(coordinates): count = 0 # make solutions - solution = [] + solution: List[str] = [] while count < x: solution.append(vector[count] / matrix[count][count]) count += 1 @@ -100,7 +102,7 @@ def points_to_polynomial(coordinates): solved = "f(x)=" while count < x: - remove_e = str(solution[count]).split("E") + remove_e: List[str] = str(solution[count]).split("E") if len(remove_e) > 1: solution[count] = remove_e[0] + "*10^" + remove_e[1] solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count]) From ba1b296b4e6703be706f7c51643fe6e1defec81b Mon Sep 17 00:00:00 2001 From: Avyakth Challa Date: Tue, 18 Aug 2020 20:07:57 +0530 Subject: [PATCH 2/3] Fixed TravisCI errors --- linear_algebra/src/polynom-for-points.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linear_algebra/src/polynom-for-points.py b/linear_algebra/src/polynom-for-points.py index adff1c4d9e35..6498a1a6c8ae 100644 --- a/linear_algebra/src/polynom-for-points.py +++ b/linear_algebra/src/polynom-for-points.py @@ -1,4 +1,5 @@ -from typing import List, Union +from typing import List + def points_to_polynomial(coordinates: List[List[int]]) -> str: """ @@ -54,7 +55,7 @@ def points_to_polynomial(coordinates: List[List[int]]) -> str: if check == 1: count_of_line: int = 0 - matrix: List[List]= [] + matrix: List[List] = [] # put the x and x to the power values in a matrix while count_of_line < x: count_in_line: int = 0 From 6ae3c9ab938eab26b8b40eba285e4104c28a6de4 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 18 Sep 2020 07:40:41 +0200 Subject: [PATCH 3/3] Update polynom-for-points.py --- linear_algebra/src/polynom-for-points.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/linear_algebra/src/polynom-for-points.py b/linear_algebra/src/polynom-for-points.py index 6498a1a6c8ae..8db89fc2c1ea 100644 --- a/linear_algebra/src/polynom-for-points.py +++ b/linear_algebra/src/polynom-for-points.py @@ -28,15 +28,15 @@ def points_to_polynomial(coordinates: List[List[int]]) -> str: f(x)=x^2*5.0+x^1*-18.0+x^0*18.0 """ try: - check: int = 1 - more_check: int = 0 - d: int = coordinates[0][0] + check = 1 + more_check = 0 + d = coordinates[0][0] for j in range(len(coordinates)): if j == 0: continue if d == coordinates[j][0]: more_check += 1 - solved: str = "x=" + str(coordinates[j][0]) + solved = "x=" + str(coordinates[j][0]) if more_check == len(coordinates) - 1: check = 2 break @@ -51,15 +51,15 @@ def points_to_polynomial(coordinates: List[List[int]]) -> str: except Exception: check = 3 - x: int = len(coordinates) + x = len(coordinates) if check == 1: - count_of_line: int = 0 - matrix: List[List] = [] + count_of_line = 0 + matrix = [] # put the x and x to the power values in a matrix while count_of_line < x: - count_in_line: int = 0 - a: int = coordinates[count_of_line][0] + count_in_line = 0 + a = coordinates[count_of_line][0] count_line: List[int] = [] while count_in_line < x: count_line.append(a ** (x - (count_in_line + 1))) @@ -74,16 +74,16 @@ def points_to_polynomial(coordinates: List[List[int]]) -> str: vector.append(coordinates[count_of_line][1]) count_of_line += 1 - count: int = 0 + count = 0 while count < x: - zahlen: int = 0 + zahlen = 0 while zahlen < x: if count == zahlen: zahlen += 1 if zahlen == x: break - bruch: int = (matrix[zahlen][count]) / (matrix[count][count]) + bruch = matrix[zahlen][count] / matrix[count][count] for counting_columns, item in enumerate(matrix[count]): # manipulating all the values in the matrix matrix[zahlen][counting_columns] -= item * bruch