From 33ecc5255438bfe0afdae0daf90bbd78e75427e1 Mon Sep 17 00:00:00 2001 From: Divlo Date: Tue, 6 Jul 2021 16:21:01 +0200 Subject: [PATCH] style: fix editorconfig-checker linting --- .../sudoku/solutions/python/function/Grid.py | 20 +++++----- .../solutions/python/function/Sudoku.py | 4 +- .../solutions/python/function/example.py | 40 ++++++++++--------- .../solutions/python/function/solution.py | 7 +--- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/challenges/sudoku/solutions/python/function/Grid.py b/challenges/sudoku/solutions/python/function/Grid.py index 8a94aae..11e3e73 100644 --- a/challenges/sudoku/solutions/python/function/Grid.py +++ b/challenges/sudoku/solutions/python/function/Grid.py @@ -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] diff --git a/challenges/sudoku/solutions/python/function/Sudoku.py b/challenges/sudoku/solutions/python/function/Sudoku.py index d1f5d50..1ed7368 100644 --- a/challenges/sudoku/solutions/python/function/Sudoku.py +++ b/challenges/sudoku/solutions/python/function/Sudoku.py @@ -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' diff --git a/challenges/sudoku/solutions/python/function/example.py b/challenges/sudoku/solutions/python/function/example.py index 1a9cfc2..2fcaa16 100644 --- a/challenges/sudoku/solutions/python/function/example.py +++ b/challenges/sudoku/solutions/python/function/example.py @@ -1,21 +1,25 @@ from Grid import Grid -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], - [4, 0, 0, 8, 0, 3, 0, 0, 1], - [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]]) +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], + [4, 0, 0, 8, 0, 3, 0, 0, 1], + [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] +]) -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], - [4, 2, 6, 8, 5, 3, 7, 9, 1], - [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]]) +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], + [4, 2, 6, 8, 5, 3, 7, 9, 1], + [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] +]) diff --git a/challenges/sudoku/solutions/python/function/solution.py b/challenges/sudoku/solutions/python/function/solution.py index fb98457..6000521 100644 --- a/challenges/sudoku/solutions/python/function/solution.py +++ b/challenges/sudoku/solutions/python/function/solution.py @@ -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)