1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00
programming-challenges/challenges/sudoku/solutions/python/function/Grid.py

29 lines
872 B
Python

from Cell import Cell
class Grid:
def __init__(self, grid: list[list[int]]) -> None:
data: list[list[Cell]] = []
for x in range(len(grid)):
column: list[Cell] = []
for y in range(len(grid[x])):
column.append(Cell(grid[x][y], y, x))
data.append(column)
self.data = data
def __repr__(self) -> str:
result: str = ''
for y in range(len(self.data)):
column = ''
for x in range(len(self.data[y])):
cell = self.get_cell(x, y)
column += str(cell.number) + ' '
result += column.rstrip()
is_last_column = (len(self.data) - 1) == y
if not is_last_column:
result += '\n'
return result
def get_cell(self, x: int, y: int) -> Cell:
return self.data[y][x]