Skip to content

Conversation

@ermmmaks
Copy link
Owner

Наконец-то понял как рекурсию реализовать (спросил). А вообще идея сохранить значения у меня уже таилась.

@ermmmaks ermmmaks requested a review from KubEF October 13, 2025 21:38
Copy link
Collaborator

Choose a reason for hiding this comment

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

Этого не должно быть в этом PR

Copy link
Owner Author

Choose a reason for hiding this comment

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

а я не понял, как оно в этой ветке образовалось. я даже не add'ил эти файлы

Copy link
Collaborator

Choose a reason for hiding this comment

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

Это не то же самое, что и src/lexicographical_order_ruff.py?

USER_SIDE = int(input("Write the lenght of the side of the field: "))


def is_valid_place(positions, n):
Copy link
Collaborator

Choose a reason for hiding this comment

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

А зачем здесь явно n?

Copy link
Owner Author

Choose a reason for hiding this comment

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

думал, так опрятнее код выглядит

Comment on lines 22 to 26
count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal)

columns.remove(column)
main_diagonal.remove(main)
collateral_diagonal.remove(collateral)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Кажется, что с битовой матрицей было бы попроще

Copy link
Owner Author

Choose a reason for hiding this comment

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

мне кажется, так нагляднее. мне переделать с матрицей?

Comment on lines 3 to 32
def queens_placement(SIDE):

def trees_from_rows(row, columns, main_diagonal, collateral_diagonal):

if row == SIDE:
return 1

count = 0

for column in range(SIDE):
main = row - column
collateral = row + column

if (column not in columns and
(main) not in main_diagonal and
(collateral) not in collateral_diagonal):

columns.add(column)
main_diagonal.add(main)
collateral_diagonal.add(collateral)

count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal)

columns.remove(column)
main_diagonal.remove(main)
collateral_diagonal.remove(collateral)

return count

return trees_from_rows(0, set(), set(), set())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Это буквально тот же код, что вы уже писали. Можно было бы импортировать. Ну или вообще не городить лишнего

1. В функции trees_from_rows вызывется цикл перебора всех колонок N раз => O(N)
2. Рекурсивный вызов со сменой строки занимает O(N - 1) (первую строку уже посчитали)

Итого: O(N * (N - 1)) ~ O(N!)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Во-первых, это не верено (я же на дискретке вас это доказать попрошу). Во-вторых, из ваших рассужданий это не следует

Copy link
Owner Author

Choose a reason for hiding this comment

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

дааа, чтото я напутал в полудрёме

Copy link
Collaborator

@KubEF KubEF left a comment

Choose a reason for hiding this comment

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

Почти совсем похоже на правду.

  1. Чистите комментарии, которые сочли решёнными (нажимайте resolve comment)
  2. Извините, порой диалога из-за загруженности тут не получается. Если тут есть что-то важное, на что я не отвечаю, тегайте в чатике

@@ -0,0 +1,18 @@
<your_inline_code>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Что это?

Comment on lines +26 to +38
user_side = int(input("Write the value of the side of the field: "))

if user_side <= len(dictionary):
print("Count of right placing: ", dictionary[user_side])
else:
user_answer = input(
"Your number is large, and the calculation may take a VERY long time. Are you willing to wait? Y/N"
)

if user_answer in "Yy":
queens_placement(user_side)
else:
print("Enter a smaller side value please")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Под if __name__ == "__main__": это

Comment on lines +36 to +38
user_side = int(input("Write the value of the side of the field: "))

print("Count of right placing: ", queens_placement(user_side))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Под if __name__ == "__main__": это

@@ -0,0 +1,25 @@
import itertools

user_side = int(input("Write the lenght of the side of the field: "))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Под if __name__ == "__main__": это

@KubEF
Copy link
Collaborator

KubEF commented Nov 1, 2025

И почините CI

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