sudoku-solver/main.py

46 lines
922 B
Python

#!/usr/bin/python3
"""This is a Sudoku Solver."""
from board import Board
def main():
"""Provided a string representing a Sudoku game, solve it."""
string = (
"..4...618\n"
"9...8....\n"
".2...6.4.\n"
"...5.34.6\n"
"7.3.1.2.5\n"
"6.94.7...\n"
".6.2...8.\n"
"....4...3\n"
"418...7..\n"
)
while '.' in string:
new_string = iterate_board(string)
assert new_string != string
string = new_string
def iterate_board(string):
"""This function consists of one iteration through the solving process.
Return an updated string.
"""
board = Board(string)
board.compute_possible_values()
board.intersect_lines_and_columns()
board.create_squares()
board.discard_with_grids()
print(f"New board:\n{board}")
return board.get_new_board()
if __name__ == '__main__':
main()