Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on: push
jobs:
build:
name: python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
uv tool install ruff
- name: Run Ruff
run: uvx ruff check --output-format=github .
62 changes: 62 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[project]
name = "py-programming"
version = "0.1.0"
description = "Homeworks"
readme = "README.md"
requires-python = ">=3.13.7"
dependencies = []

[tool.ruff]
exclude = [
".idea",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
line-length = 121
indent-width = 4
target-version = "py313"

[tool.ruff.lint]
extend-select = [
"F", # Правила Pyflakes
"W", # Предупреждения PyCodeStyle
"E", # Ошибки PyCodeStyle
"I", # Правильно сортировать импорты
"N", # Нейминг
"UP", # Предупреждать, если что-то можно изменить из-за новых версий Python
"C4", # Ловить неправильное использование comprehensions, dict, list и т.д.
"FA", # Применять from __future__ import annotations
"ISC", # Хорошее использование конкатенации строк
"ICN", # Использовать общие соглашения об импорте
"RET", # Хорошие практики возврата
"SIM", # Общие правила упрощения
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
38 changes: 38 additions & 0 deletions src/09oct25/pep8_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def count_queen_arrangements(board_size: int) -> int:
"""
Возвращает количество возможных расстановок N ферзей на шахматной доске размером NxN,
при которых ферзи не атакуют друг друга
"""

def place_queen(row_index: int, board_state: list[int]) -> int:
"""
Рекурсивно пробует расставить ферзей по строкам.
Возвращает количество корректных вариантов для текущего состояния доски
"""
# Базовый случай: если все строки заняты, найдено одно корректное решение
if row_index == board_size:
return 1
count = 0
# Перебираем возможные позиции в текущей строке
for column_index in range(board_size):
correct = True
# Проверяем, не конфликтует ли новая позиция с ранее поставленными ферзями
for prev_row in range(row_index):
if (board_state[prev_row] == column_index or
board_state[prev_row] + prev_row == column_index + row_index or
board_state[prev_row] + prev_row == column_index + row_index):
correct = False
break
# Если все нормально, пробуем поставить ферзя и продолжаем рекурсию
if correct:
board_state[row_index] = column_index
count += place_queen(row_index + 1, board_state)
return count

# Создание пустой доски
initial_board = [-1] * board_size
return place_queen(0, initial_board)


if __name__ == "__main__":
print(count_queen_arrangements(7))
2 changes: 1 addition & 1 deletion src/27sep25/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def bubble_sort(iterable):
iterable[position], iterable[position + 1] = e2, e1
return iterable

bubble_sort([3, 1, 9, 8, 11, 6])
bubble_sort([3, 1, 9, 8, 11, 6])