mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-26 02:48:40 +00:00
refactored sudoku_solver.py
This commit is contained in:
parent
af59f5cd02
commit
3237e166eb
@ -23,7 +23,7 @@ unitlist = (
|
|||||||
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
|
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
|
||||||
)
|
)
|
||||||
units = {s: [u for u in unitlist if s in u] for s in squares}
|
units = {s: [u for u in unitlist if s in u] for s in squares}
|
||||||
peers = {s: set(sum(units[s], [])) - {s} for s in squares}
|
peers = {s: set(x for u in units[s] for x in u) - {s} for s in squares}
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
@ -172,7 +172,7 @@ def solved(values):
|
|||||||
|
|
||||||
def from_file(filename, sep="\n"):
|
def from_file(filename, sep="\n"):
|
||||||
"Parse a file into a list of strings, separated by sep."
|
"Parse a file into a list of strings, separated by sep."
|
||||||
return open(filename).read().strip().split(sep) # noqa: SIM115
|
return open(filename).read().strip().split(sep)
|
||||||
|
|
||||||
|
|
||||||
def random_puzzle(assignments=17):
|
def random_puzzle(assignments=17):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user