Add initial arg to Sudoku.__init__()
This commit is contained in:
parent
eae05487b9
commit
5a32743d7b
1 changed files with 5 additions and 2 deletions
|
@ -8,13 +8,16 @@ import itertools
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class Sudoku:
|
class Sudoku:
|
||||||
def __init__(self, size=9):
|
def __init__(self, size=9, initial=None):
|
||||||
dim = math.sqrt(size)
|
dim = math.sqrt(size)
|
||||||
if dim != int(dim):
|
if dim != int(dim):
|
||||||
raise ValueError('Board size must have an integral square root.')
|
raise ValueError('Board size must have an integral square root.')
|
||||||
self._dimension = int(dim)
|
self._dimension = int(dim)
|
||||||
self.size = size
|
self.size = size
|
||||||
self.board = bytearray(b'\x00' * (size * size))
|
if initial:
|
||||||
|
self.board = bytearray(initial)[:9**2]
|
||||||
|
else:
|
||||||
|
self.board = bytearray(b'\x00' * (size * size))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dimension(self):
|
def dimension(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue