From f81935588d3191ed6a7612aa5fe02d28d2f1412c Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Thu, 9 Oct 2025 19:26:58 +0000 Subject: [PATCH 1/2] All programs have been rewritten to the PEP8 standard. --- .../Task_1/Queen-placement-v.1.0.0.py | 27 ++++++ .../Task_1/Queen-placement-v.1.1.0.py | 0 .../Task_1/Queen-placement-v.1.2.0.py | 82 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 5.Task-design/Task_1/Queen-placement-v.1.0.0.py create mode 100644 5.Task-design/Task_1/Queen-placement-v.1.1.0.py create mode 100644 5.Task-design/Task_1/Queen-placement-v.1.2.0.py diff --git a/5.Task-design/Task_1/Queen-placement-v.1.0.0.py b/5.Task-design/Task_1/Queen-placement-v.1.0.0.py new file mode 100644 index 0000000..43c5652 --- /dev/null +++ b/5.Task-design/Task_1/Queen-placement-v.1.0.0.py @@ -0,0 +1,27 @@ +import itertools + + +# Переборное решение +def enumeration_solution(n): + if n < 0: + print("Введите неотрицательное число") + return 0 + count = 0 + for permutation in itertools.permutations(range(n)): + valid = True + for i in range(n): + for j in range(i + 1, n): + if abs(i - j) == abs(permutation[i] - permutation[j]): + valid = False + break + if not valid: + break + if valid: + count += 1 + return count + + +if __name__ == "__main__": + size = int(input("Введите число N: ")) + result = enumeration_solution(size) + print(f"Количество решений: {result}") diff --git a/5.Task-design/Task_1/Queen-placement-v.1.1.0.py b/5.Task-design/Task_1/Queen-placement-v.1.1.0.py new file mode 100644 index 0000000..e69de29 diff --git a/5.Task-design/Task_1/Queen-placement-v.1.2.0.py b/5.Task-design/Task_1/Queen-placement-v.1.2.0.py new file mode 100644 index 0000000..12c0fef --- /dev/null +++ b/5.Task-design/Task_1/Queen-placement-v.1.2.0.py @@ -0,0 +1,82 @@ +from multiprocessing import Pool +from multiprocessing import cpu_count + + +# Быстрое решение +def recursive_solution(n): + if n <= 0: + print("Введите неотрицательное число") + return 0 + count = 0 + array = [0] * n + + def check(line, column): + for i in range(line): + if array[i] == column or abs(array[i] - column) == abs(i - line): + return False + return True + + def solve(line): + nonlocal count + if line == n: + count += 1 + return + + for column in range(n): + if check(line, column): + array[line] = column + solve(line + 1) + + solve(0) + return count + + +def wrapper(args): + n, first_col = args + + array = [first_col] + [0] * (n - 1) + count = 0 + + def check(line, column): + for i in range(line): + if array[i] == column or abs(array[i] - column) == abs(i - line): + return False + return True + + def solve(line): + nonlocal count + if line == n: + count += 1 + return + + for column in range(n): + if check(line, column): + array[line] = column + solve(line + 1) + + solve(1) + return count + + +def parallel_solution(n): + if n <= 0: + print("Введите неотрицательное число") + return 0 + + tasks = [(n, col) for col in range(n)] + + with Pool(processes=cpu_count()) as pool: + results = pool.map(wrapper, tasks) + + return sum(results) + + +if __name__ == "__main__": + size = int(input("Введите число N: ")) + + if size <= 8: + result = recursive_solution(size) + else: + result = parallel_solution(size) + + print(f"Количество решений: {result}") From 9940e34d267aacfc73e4a487742b870bee6f52ca Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Thu, 9 Oct 2025 19:48:58 +0000 Subject: [PATCH 2/2] Added a workflows folder with ruff --- workflows/ruff.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 workflows/ruff.yaml diff --git a/workflows/ruff.yaml b/workflows/ruff.yaml new file mode 100644 index 0000000..9340570 --- /dev/null +++ b/workflows/ruff.yaml @@ -0,0 +1,33 @@ +name: Ruff Code Check + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + ruff: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install Ruff + run: | + apt-get install -y pipx + pipx ensurepath + pipx install ruff + + - name: Run Ruff check + run: | + ruff check . +