-
Notifications
You must be signed in to change notification settings - Fork 0
Queens: 3 solutions #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ff and follow PEP8
…and linker Ruff and folow PEP8
src/lexicographical_order_ruff.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этого не должно быть в этом PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а я не понял, как оно в этой ветке образовалось. я даже не add'ил эти файлы
There was a problem hiding this comment.
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?
src/queens_on_the_table_1.py
Outdated
| USER_SIDE = int(input("Write the lenght of the side of the field: ")) | ||
|
|
||
|
|
||
| def is_valid_place(positions, n): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем здесь явно n?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
думал, так опрятнее код выглядит
src/queens_on_the_table_2.py
Outdated
| count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) | ||
|
|
||
| columns.remove(column) | ||
| main_diagonal.remove(main) | ||
| collateral_diagonal.remove(collateral) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, что с битовой матрицей было бы попроще
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
мне кажется, так нагляднее. мне переделать с матрицей?
src/queens_on_the_table_3.py
Outdated
| 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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это буквально тот же код, что вы уже писали. Можно было бы импортировать. Ну или вообще не городить лишнего
src/complexity.md
Outdated
| 1. В функции trees_from_rows вызывется цикл перебора всех колонок N раз => O(N) | ||
| 2. Рекурсивный вызов со сменой строки занимает O(N - 1) (первую строку уже посчитали) | ||
|
|
||
| Итого: O(N * (N - 1)) ~ O(N!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Во-первых, это не верено (я же на дискретке вас это доказать попрошу). Во-вторых, из ваших рассужданий это не следует
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
дааа, чтото я напутал в полудрёме
KubEF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почти совсем похоже на правду.
- Чистите комментарии, которые сочли решёнными (нажимайте resolve comment)
- Извините, порой диалога из-за загруженности тут не получается. Если тут есть что-то важное, на что я не отвечаю, тегайте в чатике
| @@ -0,0 +1,18 @@ | |||
| <your_inline_code> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что это?
| 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Под if __name__ == "__main__": это
| user_side = int(input("Write the value of the side of the field: ")) | ||
|
|
||
| print("Count of right placing: ", queens_placement(user_side)) |
There was a problem hiding this comment.
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: ")) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Под if __name__ == "__main__": это
|
И почините CI |
Наконец-то понял как рекурсию реализовать (спросил). А вообще идея сохранить значения у меня уже таилась.