# A sudoku that's already filled in for you

The usual rules of sudoku apply: each row and column must have one of each digit; plus, if you divide the whole nine-by-nine grid into nine three-by-three subgrids, then each subgrid has one of each digit. Special for this sudoku, though, some areas are heavily outlined; each of these must contain precisely the digits printed in it, with the same multiplicity.

By request, the blank grid:

This is my solution:

My approach was fairly simple:
1. Note down the possible digits for each cell, according to the rules.
2. Solve it like a usual Sudoku.

Here are the basic steps:

Put all the possible digits in the outlined areas according to the question:

Digits that appear multiple times inside one area and therefore must exist at a specific position:

Following the general Sudoku rules (specificly: unique digits in column, row and subgrids):

Some more deduction using the general Sudoku rules:

Continue to solve the Sudoku.

• Could you provide any more detail for your solution path? Even just some key deductions with pictures would be nice. Solutions to [grid-deduction] questions are generally expected to explain their solution path. Dec 17 '20 at 17:45
• @bobble Yes, I thought about that. But I actually did nothing more than draw a blank Sudoku, put all the possible digits in the outlined areas according to the question, and then solved the puzzle like a normal Sudoku. Dec 17 '20 at 17:49
• Would it be possible to show any interesting steps, or even just several picture of intermediate states? Dec 17 '20 at 17:50
• @npkllr, yes this is better. Thank you for adding more explanation Dec 17 '20 at 18:31
• @JeremyDover I added an answer that describes the constraint programming formulation. Dec 17 '20 at 20:49

You can solve the problem via constraint programming as follows. For each cell $$(i,j)$$, let integer decision variable $$x_{i,j} \in [1,9]$$ be the digit that appears in that cell. The usual sudoku rules yield 27 ALLDIFF constraints, one per row, column, or 3-by-3 box. For example, the ALLDIFF constraint for row 1 is $$\operatorname{ALLDIFF}(x_{1,1}, x_{1,2}, x_{1,3}, x_{1,4}, x_{1,5}, x_{1,6}, x_{1,7}, x_{1,8}, x_{1,9}),$$ the ALLDIFF constraint for column 1 is $$\operatorname{ALLDIFF}(x_{1,1}, x_{2,1}, x_{3,1}, x_{4,1}, x_{5,1}, x_{6,1}, x_{7,1}, x_{8,1}, x_{9,1}),$$ and the ALLDIFF constraint for the top left 3-by-3 box is $$\operatorname{ALLDIFF}(x_{1,1}, x_{1,2}, x_{1,3}, x_{2,1}, x_{2,2}, x_{2,3}, x_{3,1}, x_{3,2}, x_{3,3}).$$ For each of the 18 regions, there is also a global cardinality constraint (GCC). For example, the central plus-shaped region requires $$\operatorname{GCC}(x_{3,5}, x_{4,5}, x_{5,3}, x_{5,4}, x_{5,5}, x_{5,6}, x_{5,7}, x_{6,5}, x_{7,5}; \{(2,1,1), (3,1,1), (4,1,1), (5,1,1), (7,1,1), (8,2,2), (9,2,2)\}).$$ The interpretation is that the seven variables in the first argument must together take the values 2, 3, 4, 5, and 7 once each and the values 8 and 9 twice each.

• I don't think a programming answer is helpful when the given puzzle is already shown to be solvable by hand with logic. Dec 17 '20 at 23:48
• Hmm, I thought multiple approaches were encouraged. Dec 18 '20 at 14:20
• @Bubbler I see your point, but this is not just "I wrote a python script". Rather it is a mathematical formulation that I appreciate learning more about. Dec 19 '20 at 16:10