User:Robbiemuffin/Sudoku

The objective of Sudoku is to fill a 9×9 grid so that each column, each row, and each of the nine 3×3 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid.

Notation
Each board is divided into regions labelled A through I, and likewise each region's cels are labelled 1 through nine:

Such that you can denote the following:
 * A location
 * 1) Aii — the ii cel at region A
 * A mark in a region
 * 1) H2 — the 2 marked in region H
 * Segments
 * 1) E(top) — the top row in region E
 * 2) B(mid) — the middle row in region B
 * 3) D(right) — the right column in region D
 * 4) I(midc) — the middle column in region I

Basics
Because the rules constrain only rows, columns, and regions, the different plays tend to fit nicely in rows, columns and regions.

Necessitation
Some moves are just required. I bet you can guess how to complete this region:

Likewise with rows and columms:

Exclusion
Use numbers across regions to collaboratively narrow down choices:

{| style="background:inherit; border: none" {| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;" based exclusion''
 * style="width: 5em" |
 * style="width: 5em" |
 * + ''Row/Column
 * id="region_A" style="padding:0" |
 * id="region_B" style="padding:0" |
 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_D" style="padding:0" |


 * id="region_E" style="padding:0" |


 * id="region_F" style="padding:0" |


 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |


 * }
 * }

Implication
Implication is the first generative move. That is to say, it requires that you generate an in-between state. You can roughly think of generative moves as following a series of component-moves such that the first (and possibly successive) one requires any of a set of outcomes, but cannot specify those outcomes, while the last move takes these into account and thereby produces a specific outcome.

So, even without being able to pin down a number, if you can place it at a row or column within a region, this can place a number elsewhere:

{| style="background:inherit; border:none" {| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;" based implication''
 * style="width: 5em" |
 * style="width: 5em" |
 * + ''Row/Column
 * id="region_A" style="padding:0" |
 * id="region_B" style="padding:0" |
 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_D" style="padding:0" |


 * id="region_E" style="padding:0" |


 * id="region_F" style="padding:0" |


 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |


 * }
 * }

Implication can get quite cumbersome:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |


 * id="region_B" style="padding:0" |


 * id="region_C" style="padding:0" |


 * id="region_D" style="padding:0" |
 * id="region_E" style="padding:0" |
 * id="region_F" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_H" style="padding:0" |
 * id="region_I" style="padding:0" |
 * }
 * id="region_I" style="padding:0" |
 * }

This move reads something like a recipe.
 * Looking at 5 in context of the ABC row
 * 1) Region A's 3 and 8 require those numbers for the row to be in B or C
 * 2) the row in region B is full
 * 3) therefore there is a 3-8 pair in C
 * 4) so the row's 5 is in A
 * 5) D5 blocks the left column
 * 6) And we can pin 5 to the right column in G because:
 * 7) F5 locks the 5 to the bottom row in I
 * 8) so the entire bottom row is blocked for 5
 * 9) Leaving only right column spaces for 5 in G
 * 10) therefore G5 blocks the right column
 * 11) so A5 is in viii

Moves
Outside of easy puzzles, most puzzles cannot be solved without more advanced techniques. However, between any two of these moves, one should generally ensure that all the basic moves have satisified any uncertainties (as they are the easiest to perform, and commonly as you solve a puzzle, each solution changes the puzzle).

The Pidgeonhole Principle
I'm naming this after the Pigeonhole principle because it is a nice, near approximate and I dont know any particular name for the technique. It is perhaps a bit different than you might expect: The technique counts each possible position for each number in a region. If a particular cel in the region is left with only one number, then that number must be in that cel.

(note: this puzzle is credited to RUBYLIPS here, found from this thread at a sudoku programmer's site: Hardness measure?)

The basics do not clear any spaces. So now, to apply the pidgeonhole principle, we now mark possible moves in each region. For this example, we will use region C.

Start at 1 and work up to 9. Any number that is in the region obviously won't get any marks.

Here is a detail of the process, how to find the cels to mark for the 2s of region C:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |


 * id="region_B" style="padding:0" |


 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_D" style="padding:0" |


 * id="region_E" style="padding:0" |


 * id="region_F" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |


 * }

In the end you end up with marks like this:

''* Since we are looking for a square that only has one mark in it, we stop marking the square once it has two. This is only for convenience. It is also convenient to mark these on a scratch grid you draw on the side, if you are working on paper (although it can be done in your head).''

Now we have taken into account all possible moves in all cels in region C. If we have only one mark in a given cel, there is only one possibility in that cel, and thus a solution is found. Therefore, the number at vii is a solution via the pidgeonhole principle:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |
 * id="region_B" style="padding:0" |
 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_E" style="padding:0" |
 * id="region_F" style="padding:0" |
 * id="region_F" style="padding:0" |


 * id="region_G" style="padding:0" |
 * id="region_H" style="padding:0" |
 * id="region_I" style="padding:0" |
 * }
 * }

Naked Subsets
Looking across the board at each row and column, scan for clusters of N cels that allow only N rows or columns. (Thus, in a row or column, any three cels that can only have any of 3 numbers, or fours cels and 4 numbers, etc.)

We will examin the board's middle row and mark cels through exclusion in much the same way as in the pidgeonhole principle:

Here 7,8,9 sit alone in 3 squares. There are amung the 3 squares only 3 options, and those numbers must fill one of the select squares. The other squares in the row, therefore, cannot contain those numbers. So we can eliminate those options. In this case, that even gives us D3:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |


 * id="region_B" style="padding:0" |


 * id="region_C" style="padding:0" |


 * id="region_D" style="padding:0" |
 * id="region_E" style="padding:0" |
 * id="region_F" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |


 * }

Even if you don't win a square directly with this method, it is often still useful in the restrictions it places on remaining board possibilities.

* As an aside, it is much easier to see these when you do not need to use them, because the same effect cak be achieved through other means, than when you do.

Hidden Subsets
Hidden subsets can be thought of as related to naked subsets by their mechanism of exclusion. They are also the Row/Column version of the pidgeonhole principle. Unlike with the naked subsets, you're less likely to gestalt these coincidentally while playing, which makes it especially worthwhile to review. The following example is derrived from Sudoku Assistant - Solving Techniques

You can see that the only place in the row that 7 and 3 appear are the two highlighted cels. Therefore, those two cels must contain those two numbers. That's two numbers for two cels, therefore we can remove any other numbers from those cels.

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |
 * id="region_B" style="padding:0" |


 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_D" style="padding:0" |


 * id="region_E" style="padding:0" |


 * id="region_F" style="padding:0" |


 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |


 * }

We will continue working with this puzzle from this point in the next section.

Contingent Exclusion
Contingent exclusion is another generative move. If you are familiar with the game Snake, performing this is a little like that game but the intent is to crash into the body of the snake at a point where it turns.

Preamble
Consider this board again:

If you assumes Ci is 7, you reach a contradiction in F:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |


 * id="region_B" style="padding:0" |


 * id="region_C" style="padding:0" |
 * id="region_D" style="padding:0" |
 * id="region_E" style="padding:0" |
 * id="region_F" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |
 * id="region_G" style="padding:0" |


 * id="region_H" style="padding:0" |


 * id="region_I" style="padding:0" |
 * }

Therefore, it must be a three. This resolves the problem in F:

If you consider instead starting in region A (which sets region C), this progresses like the Snake game, setting possibilities along the way — just go from Ai to Ci to Fv. Contingent Exclusion works on the basis of chains of pairs, triplets, etc, which lead along in a path to a contradiction. This contradiction will require that the origin point must be a different option.

The Method
The example herein is from Sudoku sover, where it is credited to Mark Summerville. (Although, the name comes from a different site.)

Consider the board:

The left column has a 1,7-pair, the middle column has a 1,3,7-triplet. The B region can only have a 7 at vii or at iii, because E7 must be in the middle column. The bottom of the column pairs is also a 1,7-pair, since I7 is already played.

If we start at A and set the pair value there to 7, then G is 1. If G is 1, then H is 7. But if H is 7, then Bvii is 3. That sets Biii to 7 and we reach a contradiction:

{| class="wikitable" cellspacing=0 cellpadding=0 style="border-collapse:collapse; border: solid thin black;"
 * id="region_A" style="padding:0" |
 * id="region_B" style="padding:0" |
 * id="region_C" style="padding:0" |


 * id="region_D" style="padding:0" |
 * id="region_D" style="padding:0" |


 * id="region_E" style="padding:0" |


 * id="region_F" style="padding:0" |


 * id="region_G" style="padding:0" |
 * id="region_H" style="padding:0" |
 * id="region_I" style="padding:0" |
 * id="region_I" style="padding:0" |


 * }

Therefore, A is 1 instead. (Verifying the numbers in each cell is left as an exercise to the curious.)