From 00e5c14bbdd38332ad65776d459e258e70deac59 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 1 Apr 2023 22:46:39 +0300 Subject: [PATCH 1/5] Reduce the complexity of linear_algebra/src/polynom_for_points.py --- linear_algebra/src/polynom_for_points.py | 33 ++++-------------------- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index f5e3db0cbb13..08ca0c486c08 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -43,29 +43,13 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: x = len(coordinates) - count_of_line = 0 - matrix: list[list[float]] = [] # 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: list[float] = [] - while count_in_line < x: - count_line.append(a ** (x - (count_in_line + 1))) - count_in_line += 1 - matrix.append(count_line) - count_of_line += 1 + matrix: list[list[float]] = [[coordinates[count_of_line][0] ** (x - (count_in_line + 1)) for count_in_line in range(x)] for count_of_line in range(x)] - count_of_line = 0 # put the y values into a vector - vector: list[float] = [] - while count_of_line < x: - vector.append(coordinates[count_of_line][1]) - count_of_line += 1 + vector: list[float] = [coordinates[count_of_line][1] for count_of_line in range(x)] - count = 0 - - while count < x: + for count in range(x): zahlen = 0 while zahlen < x: if count == zahlen: @@ -79,26 +63,19 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: # manipulating the values in the vector vector[zahlen] -= vector[count] * bruch zahlen += 1 - count += 1 - count = 0 # make solutions - solution: list[str] = [] - while count < x: - solution.append(str(vector[count] / matrix[count][count])) - count += 1 + solution: list[str] = [str(vector[count] / matrix[count][count]) for count in range(x)] - count = 0 solved = "f(x)=" - while count < x: + for count in range(x): remove_e: list[str] = solution[count].split("E") if len(remove_e) > 1: solution[count] = f"{remove_e[0]}*10^{remove_e[1]}" solved += f"x^{x - (count + 1)}*{solution[count]}" if count + 1 != x: solved += "+" - count += 1 return solved diff --git a/pyproject.toml b/pyproject.toml index 48c3fbd4009d..014a37da7b06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ show-source = true target-version = "py311" [tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE -max-complexity = 17 # default: 10 +max-complexity = 10 # default: 10 [tool.ruff.pylint] # DO NOT INCREASE THESE VALUES max-args = 10 # default: 5 From 9148fde614119de6d69648f1600d9fcfc7a9b316 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 1 Apr 2023 19:47:07 +0000 Subject: [PATCH 2/5] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 34967082b359..b1adc23f6e61 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -717,6 +717,7 @@ * [Archimedes Principle](physics/archimedes_principle.py) * [Casimir Effect](physics/casimir_effect.py) * [Centripetal Force](physics/centripetal_force.py) + * [Grahams Law](physics/grahams_law.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) * [Hubble Parameter](physics/hubble_parameter.py) * [Ideal Gas Law](physics/ideal_gas_law.py) From c2bec4a7834923f4194c830ae401a4ae69c08f69 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 1 Apr 2023 19:47:56 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- linear_algebra/src/polynom_for_points.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index 08ca0c486c08..1a9643b02743 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -44,7 +44,13 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: x = len(coordinates) # put the x and x to the power values in a matrix - matrix: list[list[float]] = [[coordinates[count_of_line][0] ** (x - (count_in_line + 1)) for count_in_line in range(x)] for count_of_line in range(x)] + matrix: list[list[float]] = [ + [ + coordinates[count_of_line][0] ** (x - (count_in_line + 1)) + for count_in_line in range(x) + ] + for count_of_line in range(x) + ] # put the y values into a vector vector: list[float] = [coordinates[count_of_line][1] for count_of_line in range(x)] @@ -65,7 +71,9 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: zahlen += 1 # make solutions - solution: list[str] = [str(vector[count] / matrix[count][count]) for count in range(x)] + solution: list[str] = [ + str(vector[count] / matrix[count][count]) for count in range(x) + ] solved = "f(x)=" From aacb3c5c5575dea55d010c6c8dc735191388ef6a Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 1 Apr 2023 22:48:31 +0300 Subject: [PATCH 4/5] Fix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 014a37da7b06..48c3fbd4009d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ show-source = true target-version = "py311" [tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE -max-complexity = 10 # default: 10 +max-complexity = 17 # default: 10 [tool.ruff.pylint] # DO NOT INCREASE THESE VALUES max-args = 10 # default: 5 From 37a7aa52d5adc86b027f01c10e4c6fb7c2abc436 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sat, 5 Aug 2023 15:23:50 +0300 Subject: [PATCH 5/5] Fix review issues --- linear_algebra/src/polynom_for_points.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index 1a9643b02743..a9a9a8117c18 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -56,19 +56,15 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: vector: list[float] = [coordinates[count_of_line][1] for count_of_line in range(x)] for count in range(x): - zahlen = 0 - while zahlen < x: - if count == zahlen: - zahlen += 1 - if zahlen == x: - break - bruch = matrix[zahlen][count] / matrix[count][count] + for number in range(x): + if count == number: + continue + fraction = matrix[number][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 + matrix[number][counting_columns] -= item * fraction # manipulating the values in the vector - vector[zahlen] -= vector[count] * bruch - zahlen += 1 + vector[number] -= vector[count] * fraction # make solutions solution: list[str] = [