I am solving a sudoku and I have a list of constraints for that. They look like this:
(1,2,[1,2,3])
Each tuple contains the row number, column number and the possible values for that position. Now I have the following code to make this constraints:
[(row, column, notIn(matrix[row - 1], getColumn(matrix, column),
getSubgrid(matrix, row, column)))
for row in range(1, len(matrix) + 1)
for column in range(1, len(matrix) + 1)
if matrix[row - 1][column - 1] == 0]
I am trying to make my code more efficient and my program now makes all the constraints all the time, but I would like it to stop when it finds a constraint with only one possible value, like this:
(3,4,[2])
I want to break the list comprehension when it finds a element like this, but the element has to be included in the list. Otherwise I would like to return the constraint when I find one. It is possible that there aren't constraints with only one possible value, in that case I still need all the constraints.
How can I do this?