Conversation
Godrik0
left a comment
There was a problem hiding this comment.
Подумайте над решением за
| answer = 0 | ||
|
|
||
| coordinates = [] | ||
| for i in range(n): | ||
| for j in range(n): | ||
| coordinates.append([i, j]) #генерация всех возможных координат для ферзя | ||
| var = combinations(coordinates, n) #выбор n любых координат | ||
| for x in var: | ||
| flag = True | ||
| pool = [[0]*n for i in range(n)] | ||
| for i in range(n): #проверка что ферзи в данной выборке не бьют друг друга | ||
| row, column = x[i][0], x[i][1] | ||
| if not check(pool, row, column): | ||
| flag = False | ||
| break | ||
| pool[row][column] = 1 | ||
| if flag == True: | ||
| answer += 1 |
There was a problem hiding this comment.
Такое стоит выносить в отдельную функцию
| flag = False | ||
| break | ||
| pool[row][column] = 1 | ||
| if flag == True: |
There was a problem hiding this comment.
В Python булевые значения проверяют напрямую: if flag:
| for i in range(n): | ||
| for j in range(n): | ||
| coordinates.append([i, j]) #генерация всех возможных координат для ферзя | ||
| var = combinations(coordinates, n) #выбор n любых координат |
There was a problem hiding this comment.
Это же очень неэффективно, для переборного стоит использовать permutations
| return True | ||
|
|
||
| def next_row(r, current_board, n): | ||
| global k |
There was a problem hiding this comment.
Использовать глобальные переменные -- плохая практика. В данном случае, следовало бы возвращать из функции количество найденных значений.
| from itertools import permutations | ||
| def check(board, r, c): | ||
| for i in range(r): | ||
| if board[i] == c: # проверка столбца |
There was a problem hiding this comment.
Мы же используем permutations, тут всегда будет False
There was a problem hiding this comment.
3: E302 expected 2 blank lines, found 1
14: E305 expected 2 blank lines after class or function definition, found 1
20: E262 inline comment should start with '# '
21: E262 inline comment should start with '# '
25: E262 inline comment should start with '# '
31: E712 comparison to True should be 'if cond is True
33: W292 no newline at end of file
There was a problem hiding this comment.
3: E262 inline comment should start with '# '
5: E262 inline comment should start with '# '
9: E302 expected 2 blank lines, found 1
18: E305 expected 2 blank lines after class or function definition, found 0
21: W292 no newline at end of file
There was a problem hiding this comment.
2: E302 expected 2 blank lines, found 0
23: E712 comparison to True should be 'if cond is True
25: W292 no newline at end of file
No description provided.