mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
style: fix editorconfig-checker linting
This commit is contained in:
parent
face9ed698
commit
33ecc52554
@ -14,19 +14,17 @@ class Grid:
|
|||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
result: str = '['
|
result: str = ''
|
||||||
for y in range(len(self.data)):
|
for y in range(len(self.data)):
|
||||||
result += '['
|
column = ''
|
||||||
for x in range(len(self.data[y])):
|
for x in range(len(self.data[y])):
|
||||||
result += str(self.get_cell(x, y).number)
|
cell = self.get_cell(x, y)
|
||||||
is_last_x = x == (len(self.data[y]) - 1)
|
column += str(cell.number) + ' '
|
||||||
if not is_last_x:
|
result += column.rstrip()
|
||||||
result += ', '
|
is_last_column = (len(self.data) - 1) == y
|
||||||
result += ']'
|
if not is_last_column:
|
||||||
is_last_y = y == len(self.data) - 1
|
result += '\n'
|
||||||
if not is_last_y:
|
return result
|
||||||
result += ',\n'
|
|
||||||
return result + ']'
|
|
||||||
|
|
||||||
def get_cell(self, x: int, y: int) -> Cell:
|
def get_cell(self, x: int, y: int) -> Cell:
|
||||||
return self.data[y][x]
|
return self.data[y][x]
|
||||||
|
@ -15,8 +15,8 @@ class Sudoku:
|
|||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
result: str = '+' + '---+' * 9 + '\n'
|
result: str = '+' + '---+' * 9 + '\n'
|
||||||
for x in range(0, 9):
|
for x in range(0, 9):
|
||||||
result += ('|' + ' {} {} {} |'*3).format(*
|
format_result = [y.number for y in self.grid.data[x]]
|
||||||
[y.number if y.number != 0 else ' ' for y in self.grid.data[x]])
|
result += ('|' + ' {} {} {} |'*3).format(*format_result)
|
||||||
result += '\n'
|
result += '\n'
|
||||||
if x % 3 == 2:
|
if x % 3 == 2:
|
||||||
result += '+' + '---+' * 9 + '\n'
|
result += '+' + '---+' * 9 + '\n'
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from Grid import Grid
|
from Grid import Grid
|
||||||
|
|
||||||
grid = Grid([[5, 3, 0, 0, 7, 0, 0, 0, 0],
|
grid = Grid([
|
||||||
|
[5, 3, 0, 0, 7, 0, 0, 0, 0],
|
||||||
[6, 0, 0, 1, 9, 5, 0, 0, 0],
|
[6, 0, 0, 1, 9, 5, 0, 0, 0],
|
||||||
[0, 9, 8, 0, 0, 0, 0, 6, 0],
|
[0, 9, 8, 0, 0, 0, 0, 6, 0],
|
||||||
[8, 0, 0, 0, 6, 0, 0, 0, 3],
|
[8, 0, 0, 0, 6, 0, 0, 0, 3],
|
||||||
@ -8,9 +9,11 @@ grid = Grid([[5, 3, 0, 0, 7, 0, 0, 0, 0],
|
|||||||
[7, 0, 0, 0, 2, 0, 0, 0, 6],
|
[7, 0, 0, 0, 2, 0, 0, 0, 6],
|
||||||
[0, 6, 0, 0, 0, 0, 2, 8, 0],
|
[0, 6, 0, 0, 0, 0, 2, 8, 0],
|
||||||
[0, 0, 0, 4, 1, 9, 0, 0, 5],
|
[0, 0, 0, 4, 1, 9, 0, 0, 5],
|
||||||
[0, 0, 0, 0, 8, 0, 0, 7, 9]])
|
[0, 0, 0, 0, 8, 0, 0, 7, 9]
|
||||||
|
])
|
||||||
|
|
||||||
grid_solved = Grid([[5, 3, 4, 6, 7, 8, 9, 1, 2],
|
grid_solved = Grid([
|
||||||
|
[5, 3, 4, 6, 7, 8, 9, 1, 2],
|
||||||
[6, 7, 2, 1, 9, 5, 3, 4, 8],
|
[6, 7, 2, 1, 9, 5, 3, 4, 8],
|
||||||
[1, 9, 8, 3, 4, 2, 5, 6, 7],
|
[1, 9, 8, 3, 4, 2, 5, 6, 7],
|
||||||
[8, 5, 9, 7, 6, 1, 4, 2, 3],
|
[8, 5, 9, 7, 6, 1, 4, 2, 3],
|
||||||
@ -18,4 +21,5 @@ grid_solved = Grid([[5, 3, 4, 6, 7, 8, 9, 1, 2],
|
|||||||
[7, 1, 3, 9, 2, 4, 8, 5, 6],
|
[7, 1, 3, 9, 2, 4, 8, 5, 6],
|
||||||
[9, 6, 1, 5, 3, 7, 2, 8, 4],
|
[9, 6, 1, 5, 3, 7, 2, 8, 4],
|
||||||
[2, 8, 7, 4, 1, 9, 6, 3, 5],
|
[2, 8, 7, 4, 1, 9, 6, 3, 5],
|
||||||
[3, 4, 5, 2, 8, 6, 1, 7, 9]])
|
[3, 4, 5, 2, 8, 6, 1, 7, 9]
|
||||||
|
])
|
||||||
|
@ -15,9 +15,4 @@ for value in sys.stdin:
|
|||||||
grid = Grid(grid_values)
|
grid = Grid(grid_values)
|
||||||
sudoku = Sudoku(grid)
|
sudoku = Sudoku(grid)
|
||||||
sudoku.solve()
|
sudoku.solve()
|
||||||
|
print(sudoku.grid)
|
||||||
for row in sudoku.grid.data:
|
|
||||||
column_string = ''
|
|
||||||
for column in row:
|
|
||||||
column_string += str(column) + ' '
|
|
||||||
print(column_string.strip())
|
|
||||||
|
Loading…
Reference in New Issue
Block a user