From 37deae7ad38550faceca474f0ab1f32666ed95fb Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Wed, 15 Oct 2025 11:54:22 +0300 Subject: [PATCH 1/3] Styled and checked the biggest homework using Ruff --- .../styled_biggest_homework.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Homework #5/Code style and linters/styled_biggest_homework.py diff --git a/src/Homework #5/Code style and linters/styled_biggest_homework.py b/src/Homework #5/Code style and linters/styled_biggest_homework.py new file mode 100644 index 0000000..3237dcc --- /dev/null +++ b/src/Homework #5/Code style and linters/styled_biggest_homework.py @@ -0,0 +1,40 @@ +# Функция проверки корректности размещения ферзей по вертикали и диагонали +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]]] = [[]] +while stack: + # Нынешнее сочетание ферзей + placements: list[tuple[int, int]] = stack.pop() + + if len(placements) == N: + counter += 1 + else: + current_row = len(placements) + # Перебор возможных ферзей в пределах одной горизонтали + 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: + # Добавление сочетания, если такое возможно + stack.append(placements + [(current_row, column)]) + +print(f"The number of possible different arrangements is {counter}") From cfea0a41b1608d227090f840c76c233d5a24b3df Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Wed, 15 Oct 2025 12:06:10 +0300 Subject: [PATCH 2/3] Formatted file --- .../Code style and linters/styled_biggest_homework.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Homework #5/Code style and linters/styled_biggest_homework.py b/src/Homework #5/Code style and linters/styled_biggest_homework.py index 3237dcc..becbab5 100644 --- a/src/Homework #5/Code style and linters/styled_biggest_homework.py +++ b/src/Homework #5/Code style and linters/styled_biggest_homework.py @@ -1,7 +1,7 @@ # Функция проверки корректности размещения ферзей по вертикали и диагонали 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]): From b8fb54cae49cc5eb8f5afaf93ed793780996f066 Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Wed, 15 Oct 2025 12:11:25 +0300 Subject: [PATCH 3/3] Formatted file from another homework --- 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