Skip to content

Comments

4 hw python ferz#3

Draft
Gosha924 wants to merge 4 commits intomasterfrom
4_hw_python_ferz
Draft

4 hw python ferz#3
Gosha924 wants to merge 4 commits intomasterfrom
4_hw_python_ferz

Conversation

@Gosha924
Copy link
Owner

@Gosha924 Gosha924 commented Oct 9, 2025

No description provided.

@Gosha924 Gosha924 requested a review from chernishev October 9, 2025 13:57
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.

Рекурсивный алгоритм нужно переписать, нет реализации быстрого алгоритма

Comment on lines +9 to +22
result = 0
# проходим по всем возможным расстановкам
for perm in permutations(range(count)):
valid = True
for i in range(count):
for j in range(i + 1, count):
# проверяем есть ли ферзи на одной диагонали
if abs(perm[i] - perm[j]) == abs(i - j):
valid = False
break
if not valid:
break
if valid:
result += 1
Copy link

Choose a reason for hiding this comment

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

Лучше перенести этот код в две отдельные функции, например is_valid_permutation и count_n_queens_solutions.

Copy link

Choose a reason for hiding this comment

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

Этот файл относится к другой домашке, тут его быть не должно

if new_queen_column in old_queen:
return False
new_queen_row = len(old_queen)
for row, colum in enumerate(old_queen):
Copy link

Choose a reason for hiding this comment

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

Опечатка, column

Comment on lines +13 to +22
def rekur_ferz(count):
desk = [[]]
for i in range(count):
new_desk = []
for position in desk:
for colum in range(count):
if can_be_here_queen(colum + 1, position):
new_desk.append(position + [colum + 1])
desk = new_desk
return len(desk)
Copy link

Choose a reason for hiding this comment

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

Это точно не рекурсивная функция, рекурсивная функция должна вызывать саму себя.

Список desk будет хранить вообще все возможные валидные перестановки, с увеличением количества ферзей, там будет слишком много вариантов. Предполагается, что при рекурсивном подходе будет храниться только одна ветка.

return True


def rekur_ferz(count):
Copy link

Choose a reason for hiding this comment

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

Транслит плохо

@@ -0,0 +1,3 @@
- переборное решение O(n! * n**2)
Copy link

Choose a reason for hiding this comment

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

Можно писать формулки как в latex, если обернуть их в $$
$O(n! \cdot n^2)$

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