1
1
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:
Divlo 2021-07-06 16:21:01 +02:00
parent face9ed698
commit 33ecc52554
No known key found for this signature in database
GPG Key ID: 185ED2F15F104E52
4 changed files with 34 additions and 37 deletions

View File

@ -14,19 +14,17 @@ class Grid:
self.data = data
def __repr__(self) -> str:
result: str = '['
result: str = ''
for y in range(len(self.data)):
result += '['
column = ''
for x in range(len(self.data[y])):
result += str(self.get_cell(x, y).number)
is_last_x = x == (len(self.data[y]) - 1)
if not is_last_x:
result += ', '
result += ']'
is_last_y = y == len(self.data) - 1
if not is_last_y:
result += ',\n'
return result + ']'
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]

View File

@ -15,8 +15,8 @@ class Sudoku:
def __repr__(self) -> str:
result: str = '+' + '---+' * 9 + '\n'
for x in range(0, 9):
result += ('|' + ' {} {} {} |'*3).format(*
[y.number if y.number != 0 else ' ' for y in self.grid.data[x]])
format_result = [y.number for y in self.grid.data[x]]
result += ('|' + ' {} {} {} |'*3).format(*format_result)
result += '\n'
if x % 3 == 2:
result += '+' + '---+' * 9 + '\n'

View File

@ -1,6 +1,7 @@
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],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[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],
[0, 6, 0, 0, 0, 0, 2, 8, 0],
[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],
[1, 9, 8, 3, 4, 2, 5, 6, 7],
[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],
[9, 6, 1, 5, 3, 7, 2, 8, 4],
[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]
])

View File

@ -15,9 +15,4 @@ for value in sys.stdin:
grid = Grid(grid_values)
sudoku = Sudoku(grid)
sudoku.solve()
for row in sudoku.grid.data:
column_string = ''
for column in row:
column_string += str(column) + ' '
print(column_string.strip())
print(sudoku.grid)