Skip to content

Commit

Permalink
save set_name as a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
hhc97 committed May 13, 2020
1 parent 866abec commit 22dd0d4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,38 @@ def _populate_set_map(self) -> None:
# updates _set_map with missing symbols for each set
# and the positions they could possibly occupy within the set
for r in range(self._n):
self._set_map[f'row{r}'] = {}
set_name = f'row{r}'
self._set_map[set_name] = {}
row_set = self._row_set(r)
missing_symbols = self._symbol_set - row_set
for sym in missing_symbols:
self._set_map[f'row{r}'][sym] = set()
self._set_map[set_name][sym] = set()
for key, value in self._map.items():
if key[0] == r and sym in value:
self._set_map[f'row{r}'][sym].add(key)
self._set_map[set_name][sym].add(key)
for c in range(self._n):
self._set_map[f'col{c}'] = {}
set_name = f'col{c}'
self._set_map[set_name] = {}
col_set = self._column_set(c)
missing_symbols = self._symbol_set - col_set
for sym in missing_symbols:
self._set_map[f'col{c}'][sym] = set()
self._set_map[set_name][sym] = set()
for key, value in self._map.items():
if key[1] == c and sym in value:
self._set_map[f'col{c}'][sym].add(key)
self._set_map[set_name][sym].add(key)
n = round(self._n ** (1 / 2))
for r in range(0, self._n, n):
for c in range(0, self._n, n):
self._set_map[f'ss{r // n}{c // n}'] = {}
set_name = f'ss{r // n}{c // n}'
self._set_map[set_name] = {}
subsq_set = self._subsquare_set(r, c)
missing_symbols = self._symbol_set - subsq_set
for sym in missing_symbols:
self._set_map[f'ss{r // n}{c // n}'][sym] = set()
self._set_map[set_name][sym] = set()
for key, value in self._map.items():
if key[0] // n == r // n and key[1] // n == c // n \
and sym in value:
self._set_map[f'ss{r // n}{c // n}'][sym].add(key)
self._set_map[set_name][sym].add(key)

def get_symbols(self) -> List[List[str]]:
"""
Expand Down

0 comments on commit 22dd0d4

Please sign in to comment.