From ab927ee41d574489a93f29f974fa3c47beb81024 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 10 Oct 2017 12:54:33 -0700 Subject: [PATCH] Move some stuff around; add some docstrings --- sudoku.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sudoku.py b/sudoku.py index 1575002..13c56ef 100644 --- a/sudoku.py +++ b/sudoku.py @@ -64,6 +64,12 @@ class Sudoku: def boxes(self): return self._apply_index_ranges(self.index_boxes) + def peers(self, x, y): + ''' + Return a set of values of the peers for a given square. + ''' + return {self._board[i] for i in self.index_peers(x, y) if self._board[i] != 0} + @property def index_rows(self): ''' @@ -85,11 +91,10 @@ class Sudoku: ''' return (self._box(x, y) for (x,y) in self.all_boxes) - def peers(self, x, y): - return {self._board[i] for i in self.index_peers(x, y) if self._board[i] != 0} - def index_peers(self, x, y): - sz = self.size + ''' + Return a set of the peers, indexes into the board, for a given square. + ''' box = int(x / sz), int(y / sz) return set(self._row(y)) | set(self._column(x)) | set(self._box(*box))