Correct types, Remove comments
This commit is contained in:
parent
db2842bd0f
commit
fc3c3417e4
17
sudoku.py
17
sudoku.py
@ -57,8 +57,8 @@ def pp(c: Cell):
|
||||
|
||||
Path = list[Link]
|
||||
|
||||
def empty_grid() -> list[list[UninitializedCell]]:
|
||||
return [ [ UninitializedCell() for _j in range(9)] for _i in range(9) ]
|
||||
def empty_grid() -> list[list[Cell]]:
|
||||
return [ [ EmptyCell(i,j) for j in range(9)] for i in range(9) ]
|
||||
|
||||
class Sudoku:
|
||||
def __init__(self, grid):
|
||||
@ -91,13 +91,14 @@ class Sudoku:
|
||||
return
|
||||
yield [ [ entry for entry in row ] for row in self.grid ]
|
||||
|
||||
def read_grid() -> list[list[Cell]]:
|
||||
grid : list[list[Union[Cell,UninitializedCell]]] = empty_grid()
|
||||
@classmethod
|
||||
def read_grid(cls) -> list[list[Cell]]:
|
||||
grid : list[list[Cell]] = empty_grid()
|
||||
for i in range(9):
|
||||
row = input()
|
||||
for j in range(9):
|
||||
if row[j] == " " or row[j] == "0":
|
||||
grid[i][j] = EmptyCell(row = i, col = j)
|
||||
grid[i][j] = EmptyCell(row=i, col=j)
|
||||
else:
|
||||
grid[i][j] = GivenCell(row=i, col=j, value=int(row[j]))
|
||||
return grid
|
||||
@ -122,8 +123,8 @@ def gen_links(grid) -> Iterator[Link]:
|
||||
yield Link(c1, c2)
|
||||
|
||||
|
||||
printable = [ " ".join(list(map(pp, row))) for row in solution ]
|
||||
print("\n".join(printable))
|
||||
printable_solution = [ " ".join(list(map(pp, row))) for row in solution ]
|
||||
print("\n".join(printable_solution))
|
||||
|
||||
# build implicit graph
|
||||
links = [link for link in gen_links(solution)]
|
||||
@ -142,7 +143,6 @@ def neighbors(board: list[list[FilledCell]], cell: Cell) -> Iterator[FilledCell]
|
||||
yield board[x][y]
|
||||
|
||||
def all_cells_of_value(board: list[list[FilledCell]], filter: int) -> Iterator[FilledCell]:
|
||||
#fields = [ field for row in board for field in row ]
|
||||
fields = all_cells(board)
|
||||
for field in [ f for f in fields if f.value == filter ]:
|
||||
yield field
|
||||
@ -150,7 +150,6 @@ def all_cells_of_value(board: list[list[FilledCell]], filter: int) -> Iterator[F
|
||||
def all_cells(board: list[list[FilledCell]]) -> Iterator[FilledCell]:
|
||||
yield from [ field for row in board for field in row ]
|
||||
|
||||
# print path
|
||||
def pP(path: Path) -> str:
|
||||
return " ".join(list(map(lambda link: str(link.to.value), path)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user