44 lines
906 B
Python
Executable file
44 lines
906 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
"""This is a Sudoku Solver."""
|
|
|
|
from board import Board
|
|
|
|
|
|
def main():
|
|
"""Provided a string representing a Sudoku game, solve it."""
|
|
|
|
string = (
|
|
".....6...\n"
|
|
"..2.35.8.\n"
|
|
"....2..13\n"
|
|
".2....19.\n"
|
|
"93....7..\n"
|
|
"5....4...\n"
|
|
"1......7.\n"
|
|
".7...142.\n"
|
|
".9.4.3...\n"
|
|
)
|
|
|
|
solve_board(string, debug=False)
|
|
|
|
|
|
def solve_board(string: str, debug=False):
|
|
"""This function loops over the iteration process."""
|
|
|
|
board = Board(string, debug=debug)
|
|
iterations = 0
|
|
while '.' in string:
|
|
iterations += 1
|
|
print(board)
|
|
board.compute_possible_values()
|
|
board.compute_obligated_values()
|
|
string = board.update_string()
|
|
board.update_board()
|
|
print(board)
|
|
|
|
print(f"Solved in {iterations} iterations.")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|