Working on the solved property
This commit is contained in:
parent
53629f4d56
commit
2feef04ad9
1 changed files with 17 additions and 1 deletions
18
sudoku.py
18
sudoku.py
|
@ -15,6 +15,21 @@ class Sudoku:
|
||||||
self.size = size
|
self.size = size
|
||||||
self.board = bytearray(b'\x00' * (size * size))
|
self.board = bytearray(b'\x00' * (size * size))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def solved(self):
|
||||||
|
def _check_group(group):
|
||||||
|
values = sorted([self.board[i] for i in group])
|
||||||
|
is_complete = values == list(range(1, self.size+1))
|
||||||
|
return is_complete
|
||||||
|
|
||||||
|
sz = self.size
|
||||||
|
sz2 = sz ** 2
|
||||||
|
dim = int(math.sqrt(self.size))
|
||||||
|
|
||||||
|
rows = [range(i * sz, i * sz + sz) for i in range(sz)]
|
||||||
|
cols = [range(i, sz2, sz) for i in range(sz)]
|
||||||
|
# TODO: WIP
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
field_width = len(str(self.size))
|
field_width = len(str(self.size))
|
||||||
dim = int(math.sqrt(self.size))
|
dim = int(math.sqrt(self.size))
|
||||||
|
@ -33,5 +48,6 @@ class Sudoku:
|
||||||
lines.append('|' + '|'.join(chunks) + '|')
|
lines.append('|' + '|'.join(chunks) + '|')
|
||||||
lines.append(spacer)
|
lines.append(spacer)
|
||||||
fmt = '\n'.join(lines)
|
fmt = '\n'.join(lines)
|
||||||
out = fmt.format(board=[str(n) if n != 0 else ' ' for n in self.board])
|
str_board = [str(n) if n != 0 else ' ' for n in self.board]
|
||||||
|
out = fmt.format(board=str_board)
|
||||||
return out
|
return out
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue