Problem: Solving Sudoku Using PuLP, Part II

Learn how to solve the Sudoku problem in linear programming given a set of constraints.

Specifying the constraints

1. Each box can only have one value.

To ensure that each box has only one value, we can keep row and col constant and vary values from 1 to 9. The sum of the binary values should be equal to 1 since only one variable will be equal to 1 and others must be 0, like this:

(value = 1, row =1, col =1) + (value = 2, row =1, col =1) + (value = 3, row =1, col =1) + (value = 4, row =1, col =1) + (value = 5, row =1, col =1) + (value = 6, row =1, col =1) + (value = 7, row =1, col =1) +(value = 8, row =1, col =1) +(value = 9, row =1, col =1) == 1

We will need to perform this check for all different combinations of row and col.

Get hands-on with 1400+ tech skills courses.