From ef7aa4afafb31ab0a68f2271f0c62fe970cd6ec3 Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Tue, 28 Oct 2025 03:40:06 +0300 Subject: [PATCH 1/3] Fixed the style in Extended Euclidean algorithm\algorithm.py to pass the ruff check --- src/Homework #2/Extended Euclidean algorithm/alghoritm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Homework #2/Extended Euclidean algorithm/alghoritm.py b/src/Homework #2/Extended Euclidean algorithm/alghoritm.py index f390697..eb2d340 100644 --- a/src/Homework #2/Extended Euclidean algorithm/alghoritm.py +++ b/src/Homework #2/Extended Euclidean algorithm/alghoritm.py @@ -1,16 +1,16 @@ def extended_gcd(a: int, b: int) -> tuple[int, int, int]: x_previous, x = 1, 0 y_previous, y = 0, 1 - + while b != 0: q = a // b r = a % b - + x_previous, x = x, x_previous - q * x y_previous, y = y, y_previous - q * y - + a, b = b, r - + return a, x_previous, y_previous From 9354d2c042eb3d0f639c064892f9cc6473ee3f85 Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Tue, 28 Oct 2025 03:41:18 +0300 Subject: [PATCH 2/3] The biggest work has been stylized, and comments have been added --- .../Coding style/biggest_homework.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Homework #5/Coding style/biggest_homework.py diff --git a/src/Homework #5/Coding style/biggest_homework.py b/src/Homework #5/Coding style/biggest_homework.py new file mode 100644 index 0000000..ef3b674 --- /dev/null +++ b/src/Homework #5/Coding style/biggest_homework.py @@ -0,0 +1,43 @@ +# A function that verifies the correct placement of the queen vertically and diagonally +def is_safe_direction( + coordinate_1: tuple[int, int], + coordinate_2: tuple[int, int], + ) -> bool: + if coordinate_1[1] == coordinate_2[1] or abs( + coordinate_1[1] - coordinate_2[1], + ) == abs(coordinate_1[0] - coordinate_2[0]): + return False + return True + + +N = int(input("Enter the value N: ")) + +board_size = N**2 + +counter = 0 + + +stack: list[list[tuple[int, int]]] = [[]] +# The main loop, sorting through the number of combinations of possible placements +# and putting them on the stack +while stack: + # Get the last placement from the top of the stack + placements: list[tuple[int, int]] = stack.pop() + + # Check the numebr of placements + if len(placements) == N: + counter += 1 + else: + current_row = len(placements) + # Go through the values of possible placements within the same horizontal + for column in range(N): + for placement_column, placement_row in placements: + if not is_safe_direction( + (placement_column, placement_row), (current_row, column), + ): + break + else: + # Add the placement to the stack if possible + stack.append(placements + [(current_row, column)]) + +print(f"The number of possible different arrangements is {counter}") From 2d03c87606f587dd96b1ffcc5a1eebe5e892f111 Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Tue, 28 Oct 2025 03:46:33 +0300 Subject: [PATCH 3/3] Fixed small style bugs in algorithm.py and biggest_homework.py --- .../Extended Euclidean algorithm/alghoritm.py | 2 +- src/Homework #5/Coding style/biggest_homework.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Homework #2/Extended Euclidean algorithm/alghoritm.py b/src/Homework #2/Extended Euclidean algorithm/alghoritm.py index eb2d340..d2859ad 100644 --- a/src/Homework #2/Extended Euclidean algorithm/alghoritm.py +++ b/src/Homework #2/Extended Euclidean algorithm/alghoritm.py @@ -18,4 +18,4 @@ def extended_gcd(a: int, b: int) -> tuple[int, int, int]: print(f"GCD(54, 30) = {d}") print(f"Coefficients: x = {x}, y = {y}") -print(f"Factorization: 54*({x}) + 30*({y}) = {54*x + 30*y}") +print(f"Factorization: 54*({x}) + 30*({y}) = {54 * x + 30 * y}") diff --git a/src/Homework #5/Coding style/biggest_homework.py b/src/Homework #5/Coding style/biggest_homework.py index ef3b674..fea42ff 100644 --- a/src/Homework #5/Coding style/biggest_homework.py +++ b/src/Homework #5/Coding style/biggest_homework.py @@ -1,8 +1,8 @@ # A function that verifies the correct placement of the queen vertically and diagonally def is_safe_direction( - coordinate_1: tuple[int, int], - coordinate_2: tuple[int, int], - ) -> bool: + coordinate_1: tuple[int, int], + coordinate_2: tuple[int, int], +) -> bool: if coordinate_1[1] == coordinate_2[1] or abs( coordinate_1[1] - coordinate_2[1], ) == abs(coordinate_1[0] - coordinate_2[0]): @@ -33,7 +33,8 @@ def is_safe_direction( for column in range(N): for placement_column, placement_row in placements: if not is_safe_direction( - (placement_column, placement_row), (current_row, column), + (placement_column, placement_row), + (current_row, column), ): break else: