-
Notifications
You must be signed in to change notification settings - Fork 60
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
Homework02 Плешнев Арсений 467106 К24 1.2 #150
Homework02 Плешнев Арсений 467106 К24 1.2 #150
Conversation
fixed mypy and generating issues
black fix
В качестве защиты нужно сделать ревью этой лабораторной - #241 |
Ревью работы коллеги хорошее |
digits = [c for c in puzzle if c in "123456789."] | ||
grid = group(digits, 9) |
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.
Наблюдается использование двух имен (grid и ngrid) для одной и той же логики. Это создает путаницу.
|
||
|
||
def get_block(grid: tp.List[tp.List[str]], pos: tp.Tuple[int, int]) -> tp.List[str]: | ||
def get_block(ngrid: tp.List[tp.List[str]], pos: tp.Tuple[int, int]) -> tp.List[str]: |
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.
get_block можно оптимизировать, используя срезы.
['2', '8', '.', '.', '.', '5', '.', '7', '9'] | ||
""" | ||
pass |
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.
почти в каждой функции присутствует pass, хотя фактически он не нужен
|
||
|
||
def find_empty_positions(grid: tp.List[tp.List[str]]) -> tp.Optional[tp.Tuple[int, int]]: |
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.
find_empty_positions: Вместо магического значения (1000, 1000) лучше возвращать None, если пустых клеток нет
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.
Если внесете правки к 28 января, баллов хватит, чтобы закрыться
length = len(values) | ||
|
||
newls: tp.List[tp.List[T]] = [[] for _ in range(length // n)] | ||
|
||
for index, i in enumerate(values): | ||
newls[index // n].append(i) | ||
|
||
return newls |
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.
Функция будет более читаемой, если оформите ее в виде спискового включения
newls = [ngrid[i][pos[1]] for i in range(len(ngrid))] | ||
|
||
return newls |
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.
Можно сразу так return [ngrid[i][pos[1]] for i in range(len(ngrid))]
values = find_possible_values(ngrid, pos) | ||
if values == None: | ||
return None |
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 not values:
return None
g = solve(ngrid) | ||
|
||
if g == None: |
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 not solve(ngrid):
...
if row.count(n) == 1 and col.count(n) == 1 and block.count(n) == 1: | ||
continue | ||
else: | ||
return False |
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.
Лучше заменить на сокращенный условный оператор и обойтись без continue
# def random_gen(): | ||
# grid = [["." for _ in range(9)] for _ in range(9)] |
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.
Лишним комментам не место в коде
|
||
|
||
""" | ||
def generate_sudoku(N: int) -> tp.List[tp.List[str]]: | ||
'''Генерация судоку заполненного на N элементов | ||
>>> grid = generate_sudoku(40) | ||
>>> sum(1 for row in grid for e in row if e == '.') | ||
41 | ||
>>> solution = solve(grid) | ||
>>> check_solution(solution) | ||
True | ||
>>> grid = generate_sudoku(1000) | ||
>>> sum(1 for row in grid for e in row if e == '.') | ||
0 | ||
>>> solution = solve(grid) |
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.
Это тоже лишний коммент
No description provided.