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 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]

View File

@ -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'

View File

@ -1,21 +1,25 @@
from Grid import Grid from Grid import Grid
grid = Grid([[5, 3, 0, 0, 7, 0, 0, 0, 0], grid = Grid([
[6, 0, 0, 1, 9, 5, 0, 0, 0], [5, 3, 0, 0, 7, 0, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3], [0, 9, 8, 0, 0, 0, 0, 6, 0],
[4, 0, 0, 8, 0, 3, 0, 0, 1], [8, 0, 0, 0, 6, 0, 0, 0, 3],
[7, 0, 0, 0, 2, 0, 0, 0, 6], [4, 0, 0, 8, 0, 3, 0, 0, 1],
[0, 6, 0, 0, 0, 0, 2, 8, 0], [7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 6, 0, 0, 0, 0, 2, 8, 0],
[0, 0, 0, 0, 8, 0, 0, 7, 9]]) [0, 0, 0, 4, 1, 9, 0, 0, 5],
[0, 0, 0, 0, 8, 0, 0, 7, 9]
])
grid_solved = Grid([[5, 3, 4, 6, 7, 8, 9, 1, 2], grid_solved = Grid([
[6, 7, 2, 1, 9, 5, 3, 4, 8], [5, 3, 4, 6, 7, 8, 9, 1, 2],
[1, 9, 8, 3, 4, 2, 5, 6, 7], [6, 7, 2, 1, 9, 5, 3, 4, 8],
[8, 5, 9, 7, 6, 1, 4, 2, 3], [1, 9, 8, 3, 4, 2, 5, 6, 7],
[4, 2, 6, 8, 5, 3, 7, 9, 1], [8, 5, 9, 7, 6, 1, 4, 2, 3],
[7, 1, 3, 9, 2, 4, 8, 5, 6], [4, 2, 6, 8, 5, 3, 7, 9, 1],
[9, 6, 1, 5, 3, 7, 2, 8, 4], [7, 1, 3, 9, 2, 4, 8, 5, 6],
[2, 8, 7, 4, 1, 9, 6, 3, 5], [9, 6, 1, 5, 3, 7, 2, 8, 4],
[3, 4, 5, 2, 8, 6, 1, 7, 9]]) [2, 8, 7, 4, 1, 9, 6, 3, 5],
[3, 4, 5, 2, 8, 6, 1, 7, 9]
])

View File

@ -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())