Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sudoku_chart():
- def __init__(self, dim=9, block_dim=3):
- self.dim=dim #размер матрицы (9*9)
- self.block_dim=block_dim #размер блока (3*3)
- self.matrix=map(list,[[None]*dim]*dim)
- def _get_row(self, row):
- return self.matrix[row]
- def _get_col(self, col):
- return [row[col] for row in self.matrix]
- def _get_block(self, block_x, block_y): #x, y - координаты блока (00, 01, 02)
- x=self.block_dim*block_x # (10, 11, 12)
- y=self.block_dim*block_y # (20, 21, 22)
- values=set()
- for row in self.matrix[y:y+self.block_dim]:
- values.update(row[x:x+self.block_dim])
- return values
- def get_cross(self, row, col):
- values=set()
- values.update(self._get_row(row),
- self._get_col(col),
- self._get_block(col/self.block_dim,
- row/self.block_dim))
- return values
- def set_cell(self, row, col, value):
- self.matrix[row][col]=value
- def __repr__(self):
- output=str()
- for row in self.matrix:
- for block in xrange(0, self.dim, self.block_dim):
- for val in row[block:block+self.block_dim]:
- output+=str(val)+', '
- output+='\t'
- output+='\n'
- return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement