Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solve_sudoku(sudoku: list) -> list or None:
- """
- Function which solves sudoku
- :param sudoku: 2d list that represents sudoku, empty spaces should be marked as 0
- :return: returns solution or None
- """
- solved = sudoku.copy()
- empty_spaces = find_empty(sudoku)
- counter = 0
- correct = False
- while 0 <= counter < len(empty_spaces):
- i, j = empty_spaces[counter]
- for tested_value in range(solved[i][j] + 1, 10):
- correct = is_correct(tested_value, solved, (i, j))
- if correct:
- solved[i][j] = tested_value
- break
- if correct:
- counter += 1
- else:
- solved[i][j] = 0
- counter -= 1
- if correct:
- return solved
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement