Skip to content

Hm3#6

Open
ialina07 wants to merge 1 commit intomainfrom
hm3
Open

Hm3#6
ialina07 wants to merge 1 commit intomainfrom
hm3

Conversation

@ialina07
Copy link
Owner

@ialina07 ialina07 commented Oct 9, 2025

Решения задачи о расстановке ферзей

@ialina07 ialina07 requested a review from chernishev October 9, 2025 21:08
Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уберите лишние файлы из PR и сделайте что-то с тестами, подробнее -- в комментариях.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот файл не относится к этому заданию, уберите его из PR

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот файл тоже не относится к этому заданию, уберите его из PR

Comment on lines +10 to +25
count = 0
# Доступные позиции в текущей строке
available_positions = ((1 << n) - 1) & ~(columns | diagonals1 | diagonals2)

while available_positions:
# Берем самую правую доступную позицию
position = available_positions & -available_positions
# Убираем ее из доступных
available_positions -= position

count += backtrack(
row + 1,
columns | position,
(diagonals1 | position) << 1,
(diagonals2 | position) >> 1,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Всю эту логику стоит пояснить подробнее.
Например, что происходит в этих строчках?

columns | position,
(diagonals1 | position) << 1,
(diagonals2 | position) >> 1

Вернувшись к ним через время вы уже и не сможете точно вспомнить.

Comment on lines +32 to +65
def test_bitmask_basic():
"""Тест оптимизированного решения (bitmask)"""
print("ТЕСТИРОВАНИЕ BITMASK РЕШЕНИЯ")
print("=" * 50)

# Известные значения для N ферзей
test_cases = [
(1, 1), # [0]
(2, 0), # нет решений
(3, 0), # нет решений
(4, 2), # 2 решения
(5, 10), # 10 решений
(6, 4), # 4 решения
(7, 40), # 40 решений
(8, 92), # 92 решения
(9, 352), # 352 решения
(10, 724), # 724 решения
]

all_passed = True

for n, expected in test_cases:
result = n_queens_bitmask(n)

if result == expected:
print(f"✓ N={n}: {result} (ожидалось {expected})")
else:
print(f"✗ N={n}: {result} (ожидалось {expected})")
all_passed = False

print("=" * 50)
print(f"РЕЗУЛЬТАТ: {'Все тесты пройдены' if all_passed else 'Есть ошибки'}")

return all_passed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тесты в этом задании не предполагались, тем более тут они очень захардкожены через print. Лучше либо уберите их, либо перепишите, используя pytest.

Comment on lines +15 to +16
if count is None:
count = [0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем тут передавать список count? Можно было бы сделать так, чтобы функция возвращала количество решений из своей ветки, а в основной ветке они суммировались.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants