Sudoku training is challenging. Sudoku solving algorithm (Sudoku)

Sudoku is an interesting puzzle for training logic, unlike crossword puzzles, where erudition and memory are needed. Sudoku has many countries of origin, one way or another, it was played in Ancient China, Japan, North America ... In order for us to learn the game, we made a selection How to solve Sudoku from easy to hard.

To begin with, let's say that Sudoku is a 9x9 square, which in turn consists of 9 3x3 squares. Each square must be filled with numbers from one to nine so that each number is used only once in a vertical and horizontal line, and only in a 3x3 square.

When you fill in all the cells, you should get all the numbers from 1 to 9 in each of the 9 squares. So, along the horizontal line, all the numbers from 1 to 9. And the same thing along the vertical line, see the picture:

It would seem that there are simple rules, but in order to answer the question of how to solve Sudoku, and even more so, if you want to know how to solve complex Sudoku (especially for those who are just starting their journey), you need to solve at least a couple of easy tasks. Then it will be clear what it is about. Below are the games. Try printing them out and filling them in so that everything fits together:


How to solve difficult sudoku

I hope you have read the text above and solved the task that you need in order to understand what will be discussed next. If yes, then we continue.

This part of the article will answer the questions:

How to solve difficult sudoku?

How to solve Sudoku: ways?

How to solve Sudoku: ways and methods of cells and fields?

So, you were given two games, by solving which you acquired skills and got a general idea. In order to save your time, I will tell you a couple of life hacks for solving Sudoku quickly.

1. Always start with the number 1 and go first along the lines, and then along the squares. So you definitely will not get confused and warn yourself against many mistakes.

2. Always check which number is missing where there are fewer empty cells left. This will save time. And be sure to pay attention to how many and what numbers are missing in the 3 by 3 square (both on the horizontal and vertical lines).

3. If there are many empty cells in the square and you are at a dead end, try to mentally divide the square along the lines. Think about what numbers can be there, and based on this you can understand what numbers will be on the same lines in other squares (and you may even understand what numbers will be in other squares on another line).

4. Don't be afraid of anything, it's better to make a mistake and understand why than to do nothing!

5. More practice and you will become a master.

And if people who solve Sudoku also have abstract intelligence, which gives a powerful potential for its owner, then you can move far ahead. Read more about such people.

Below you will find a selection of "How to solve complex Sudoku", after which you will be able to do a lot!



So today I will teach you solve sudoku.

For clarity, let's take a specific example and consider the basic rules:

Sudoku solving rules:

I highlighted the row and column in yellow. First rule each row and each column can contain numbers from 1 to 9, and they cannot be repeated. In short - 9 cells, 9 numbers - therefore, in the 1st and the same column there cannot be 2 fives, eights, etc. Likewise for strings.

Now I have selected the squares - this is second rule. Each square can contain numbers from 1 to 9 and they are not repeated. (Same as in rows and columns). The squares are marked with bold lines.

Hence we have general rule for solving sudoku: neither in lines, nor in columns neither in squares numbers must not be repeated.

Well, let's try to solve it now:

I've highlighted the units in green and shown the direction we're looking. Namely, we are interested in the last upper square. You may notice that in the 2nd and 3rd rows of this square there cannot be units, otherwise there will be a repetition. So - unit at the top:

It is easy to find a deuce:

Now let's use the two we just found:

I hope the search algorithm has become clear, so from now on I will draw faster.

We look at the 1st square of the 3rd line (below):

Because we have 2 free cells left there, then each of them can have one of two numbers: (1 or 6):

This means that in the column that I highlighted there can no longer be either 1 or 6 - so we put 6 in the upper square.

For lack of time, I will stop here. I really hope you get the logic. By the way, I took not the simplest example, in which most likely all solutions will not be immediately visible unambiguously, and therefore it is better to use a pencil. We don't know about 1 and 6 in the bottom square yet, so we draw them with a pencil - similarly, 3 and 4 will be drawn in pencil in the top square.

If we think a little more, using the rules, we will get rid of the question where is 3, and where is 4:

Yes, by the way, if some point seemed incomprehensible to you, write, and I will explain in more detail. Good luck with sudoku.


The Sudoku field is a table of 9x9 cells. A number from 1 to 9 is entered in each cell. The goal of the game is to arrange the numbers in such a way that there are no repetitions in each row, column and each 3x3 block. In other words, each column, row, and block must contain all the numbers from 1 to 9.

To solve the problem, candidates can be written in empty cells. For example, consider a cell in the 2nd column of the 4th row: in the column in which it is located, there are already numbers 7 and 8, in the row - numbers 1, 6, 9 and 4, in the block - 1, 2, 8 and 9 Therefore, we cross out 1, 2, 4, 6, 7, 8, 9 from the candidates in this cell, and we are left with only two possible candidates - 3 and 5.

Similarly, we consider possible candidates for other cells and get the following table:

Candidates are more interesting to deal with and different logical methods can be applied. Next, we will look at some of them.

Loners

The method consists in finding singles in the table, i.e. cells in which only one digit is possible and no other. We write this number in this cell and exclude it from other cells of this row, column and block. For example: in this table there are three "loners" (they are highlighted in yellow).

hidden loners

If there are several candidates in a cell, but one of them is not found in any other cell of a given row (column or block), then such a candidate is called a “hidden loner”. In the following example, candidate "4" in the green block is only found in the center cell. So, in this cell there will definitely be “4”. We enter "4" in this cell and cross it out from other cells of the 2nd column and 5th row. Similarly, in the yellow column, the candidate "2" occurs once, therefore, we enter "2" in this cell and exclude "2" from the cells of the 7th row and the corresponding block.

The previous two methods are the only methods that uniquely determine the contents of a cell. The following methods only allow you to reduce the number of candidates in the cells, which will sooner or later lead to loners or hidden loners.

Locked Candidate

There are times when a candidate within a block is in only one row (or one column). Due to the fact that one of these cells will necessarily contain this candidate, this candidate can be excluded from all other cells of this row (column).

In the example below, the center block contains candidate "2" only in the center column (yellow cells). So one of those two cells must definitely be "2", and no other cells in that row outside of this block can be "2". Therefore, "2" can be excluded as a candidate from other cells in this column (cells in green).

Open Pairs

If two cells in a group (row, column, block) contain an identical pair of candidates and nothing else, then no other cells in this group can have the value of this pair. These 2 candidates can be excluded from other cells in the group. In the example below, candidates "1" and "5" in columns eight and nine form an Open Pair within the block (yellow cells). Therefore, since one of these cells must be "1" and the other must be "5", candidates "1" and "5" are excluded from all other cells of this block (green cells).

The same can be formulated for 3 and 4 candidates, only 3 and 4 cells are already participating, respectively. Open triples: from the green cells, we exclude the values ​​of the yellow cells.

Open fours: from the green cells, we exclude the values ​​of the yellow cells.

hidden couples

If two cells in a group (row, column, block) contain candidates, among which there is an identical pair that does not occur in any other cell of this block, then no other cells of this group can have the value of this pair. Therefore, all other candidates of these two cells can be excluded. In the example below, candidates "7" and "5" in the central column are only in yellow cells, which means that all other candidates from these cells can be excluded.

Similarly, you can look for hidden triples and fours.

x-wing

If a value has only two possible locations in a row (column), then it must be assigned to one of those cells. If there is one more row (column), where the same candidate can also be in only two cells and the columns (rows) of these cells are the same, then no other cell of these columns (rows) can contain this number. Consider an example:

In the 4th and 5th lines, the number "2" can only be in two yellow cells, and these cells are in the same columns. Therefore, the number "2" can be written in only two ways: 1) if "2" is written in the 5th column of the 4th row, then "2" must be excluded from the yellow cells and then in the 5th row the position "2" is uniquely determined by the 7th column.

2) if “2” is written in the 7th column of the 4th row, then “2” must be excluded from the yellow cells and then in the 5th row the position “2” is uniquely determined by the 5th column.

Therefore, the 5th and 7th columns will necessarily have the number "2" either in the 4th row or in the 5th. Then the number "2" can be excluded from other cells of these columns (green cells).

"Swordfish" (Swordfish)

This method is a variation of the .

It follows from the rules of the puzzle that if a candidate is in three rows and only in three columns, then in other rows this candidate in these columns can be excluded.

Algorithm:

  • We are looking for lines in which the candidate occurs no more than three times, but at the same time it belongs to exactly three columns.
  • We exclude the candidate from these three columns from other rows.

The same logic applies in the case of three columns, where the candidate is limited to three rows.

Consider an example. In three lines (3rd, 5th and 7th) candidate "5" occurs no more than three times (cells are highlighted in yellow). However, they belong to only three columns: 3rd, 4th and 7th. According to the “Swordfish” method, candidate “5” can be excluded from other cells of these columns (green cells).

In the example below, the Swordfish method is also applied, but for the case of three columns. We exclude the candidate "1" from the green cells.

"X-wing" and "Swordfish" can be generalized to four rows and four columns. This method will be called "Medusa".

Colors

There are situations when a candidate occurs only twice in a group (in a row, column or block). Then the desired number will definitely be in one of them. The strategy for the Colors method is to view this relationship using two colors, such as yellow and green. In this case, the solution can be in the cells of only one color.

We select all interconnected chains and make a decision:

  • If some unshaded candidate has two differently colored neighbors in a group (row, column, or block), then it can be excluded.
  • If there are two identical colors in a group (row, column or block), then this color is false. A candidate from all cells of this color can be excluded.

In the following example, apply the "Colors" method to cells with candidate "9". We start coloring from the cell in the upper left block (2nd row, 2nd column), paint it yellow. In its block, it has only one neighbor with "9", let's paint it green. She also has only one neighbor in the column, we paint over it in green.

Similarly, we work with the rest of the cells containing the number "9". We get:

Candidate "9" can be either only in all yellow cells, or in all green. In the right middle block, two cells of the same color met, therefore, the green color is incorrect, since this block produces two "9s", which is unacceptable. We exclude, "9" from all green cells.

Another example of the "Colors" method. Let's mark paired cells for the candidate "6".

The cell with "6" in the upper central block (highlighted in lilac) has two multi-colored candidates:

"6" will necessarily be in either a yellow or green cell, therefore, "6" can be excluded from this lilac cell.

All the same, almost everyone can solve this puzzle. The main thing is to choose your level of difficulty on the shoulder. Sudoku is an interesting puzzle game that keeps your sleepy brain and free time busy. In general, anyone who has tried to solve it has already managed to identify some patterns. The more you solve it, the better you begin to understand the principles of the game, but the more you want to somehow improve your way of solving. Since the advent of Sudoku, people have developed many different ways to solve, some easier, some more difficult. Below is a sample set of basic hints and some of the more basic methods for solving Sudoku. First, let's define terminology.

Sophisticated fans can buy a desktop version of Sudoku at ozon.ru

Terminology

Method 1: Singles

Singles (single variants) may be defined by excluding digits already present in rows, columns or areas. The following methods allow you to solve most of the "simple" variants of Sudoku.

1.1 Obvious singles

Since these pairs are both in the third area (upper right), we can also exclude the numbers 1 and 4 from the rest of the cells in this area.

When three cells in one group contain no candidates other than three, those numbers can be excluded from the remaining cells of the group.

Please note: it is not necessary that these three cells contain all the numbers of the trio! It is only necessary that these cells do not contain other candidates.

In this row we have a trio 1,4,6 in cells A, C and G, or two candidates from this trio. These three cells will necessarily contain all three candidates. Therefore, they cannot be elsewhere in this neighborhood, and therefore can be excluded from other cells (E and F).

Similarly, for a quartet, if four cells contain no other candidates than from one quartet, these numbers can be excluded from other cells in this group. As with a trio, cells containing a quartet are not required to contain all four quartet candidates.

3.2 Hidden groups of candidates

For obvious candidate groups (previous method: 3.1), pairs, trios, and quartets allowed candidates to be excluded from other cells in the group.
In this method, hidden candidate groups allow other candidates to be excluded from the cells containing them.

If there are N cells (2,3 or 4) containing N common numbers (and they do not occur in other cells of the group), then the remaining candidates for these cells can be excluded.

In this row, the pair (4,6) occurs only in cells A and C.

The remaining candidates can thus be excluded from these two cells, since they must contain either 4 or 6 and no others.

As with the obvious trios and quartets, the cells do not have to contain all the numbers in the trio or quartet. Hidden trios are very difficult to see. Fortunately, they are not often used to solve Sudoku.
Hidden quartets are almost impossible to see!

Rule 4: Complex methods.

4.1. Connected couples (butterfly)

The following methods are not necessarily more difficult to understand than those described above, but it is not easy to determine when they should be applied.

This method can be applied to areas:

As in the previous example, two columns (B and C), where 9 can only be in two cells (B3 and B9, C2 and C8).

Since B3 and C2, as well as B9 and C8, are inside the same area (and not in the same row as in the previous example), 9 can be excluded from the remaining cells of these two areas.

4.2 Complex pairs (fish)

This method is a more complex version of the previous one (4.1 Connected Pairs).

You can apply it when one of the candidates is present in no more than three rows and in all rows they are in the same three columns.

The goal of Sudoku is to arrange all the numbers so that there are no identical numbers in 3x3 squares, rows and columns. Here is an example of a Sudoku already solved:


You can check that there are no repeating numbers in each of the nine squares, as well as in all rows and columns. When solving Sudoku, you need to use this number “uniqueness” rule and, sequentially excluding candidates (small numbers in a cell indicate which numbers, in the player’s opinion, can stand in this cell), find places where only one number can stand.

When we open the Sudoku, we see that each cell contains all the little gray numbers. You can immediately uncheck the already set numbers (marks are removed by right-clicking on a small number):


I'll start with the number that is in this crossword puzzle in one copy - 6, so that it would be more convenient to show the exclusion of candidates.


Numbers are excluded in the square with the number, in the row and column, the candidates to be removed are marked in red - we will right-click on them, noting that there cannot be sixes in these places (otherwise there will be two sixes in the square / column / row, which is against the rules).

Now, if we return to units, then the pattern of exceptions will be as follows:


We remove candidates 1 in each free cell of the square where there is already a 1, in each row where there is a 1 and in each column where there is a 1. In total, for three units there will be 3 squares, 3 columns and 3 rows.

Next, let's go straight to 4, there are more numbers, but the principle is the same. And if you look closely, you can see that in the upper left 3x3 square there is only one free cell (marked in green), where 4 can stand. So, put the number 4 there and erase all the candidates (there can no longer be other numbers). In simple Sudoku, quite a lot of fields can be filled in this way.


After a new number is set, you can double-check the previous ones, because adding a new number narrows the search circle, for example, in this crossword puzzle, thanks to the four set, there is only one cell left in this square (green):


Of the three available cells, only one is not occupied by the unit, and we put the unit there.

Thus, we remove all obvious candidates for all numbers (from 1 to 9) and put down the numbers if possible:


After removing all obviously unsuitable candidates, a cell was obtained where only 1 candidate (green) remained, which means that this number is three, and it is worth it.

The numbers are also put if the candidate is the last in the square, row or column:



These are examples on fives, you can see that there are no fives in the orange cells, and the only candidate in the region remains in the green cells, which means that the fives are there.

These are the most basic ways to put numbers in Sudoku, you can already try them out by solving Sudoku on simple difficulty (one star), for example: Sudoku No. 12433, Sudoku No. 14048, Sudoku No. 526. Sudokus shown are completely solved using the information above. But if you can’t find the next number, you can resort to the selection method - save the Sudoku, and try to put down some number at random, and in case of failure, load the Sudoku.

If you want to learn more complex methods, read on.

Locked Candidates

Locked Candidate in a Square

Consider the following situation:


In the square highlighted in blue, the number 4 candidates (green cells) are located in two cells on the same line. If the number 4 is on this line (orange cells), then there will be nowhere to put 4 in the blue square, which means that we exclude 4 from all orange cells.

A similar example for the number 2:


Locked candidate in a row

This example is similar to the previous one, but here in row (blue) candidates 7 are in the same square. This means that sevens are removed from all the remaining cells of the square (orange).


Locked Candidate in a Column

Similar to the previous example, only in the column 8 candidates are located in the same square. All candidates 8 from other cells of the square are also removed.


Having mastered the locked candidates, you can solve Sudoku of medium difficulty without selection, for example: Sudoku No. 11466, Sudoku No. 13121, Sudoku No. 11528.

Number groups

Groups are harder to see than locked candidates, but they help clear many dead ends in complex crossword puzzles.

naked couples

The simplest subspecies of groups are two identical pairs of numbers in one square, row or column. For example, a bare pair of numbers in a string:


If in any other cell in the orange line there is 7 or 8, then in the green cells there will be 7 and 7, or 8 and 8, but according to the rules it is impossible for the line to have 2 identical numbers, so all 7 and all 8 are removed from the orange cells .

Another example:


A naked couple is in the same column and in the same square at the same time. Extra candidates (red) are removed both from the column and from the square.

An important note - the group must be exactly “naked”, that is, it must not contain other numbers in these cells. That is, and are a naked group, but and are not, since the group is no longer naked, there is an extra number - 6. They are also not a naked group, since the numbers must be the same, but here there are 3 different numbers in the group.

Naked triplets

Naked triples are similar to naked pairs, but they are more difficult to detect - these are 3 naked numbers in three cells.


In the example, the numbers in one line are repeated 3 times. There are only 3 numbers in the group and they are located on 3 cells, which means that the extra numbers 1, 2, 6 from the orange cells are removed.

A naked triple may not contain a number in full, for example, a combination would be suitable:, and - these are all the same 3 types of numbers in three cells, just in an incomplete composition.

Naked Fours

The next extension of bare groups is bare fours.


Numbers , , , form a bare quadruple of four numbers 2, 5, 6 and 7 located in four cells. This quadruple is located in one square, which means that all the numbers 2, 5, 6, 7 from the remaining cells of the square (orange) are removed.

hidden couples

The next variation of groups is hidden groups. Consider an example:


In the topmost line, the numbers 6 and 9 are located only in two cells; there are no such numbers in the other cells of this line. And if you put another number in one of the green cells (for example, 1), then there will be no room left in the line for one of the numbers: 6 or 9, so you need to delete all the numbers in the green cells, except for 6 and 9.

As a result, after removing the excess, only a bare pair of numbers should remain.

Hidden triplets

Similar to hidden pairs - 3 numbers stand in 3 cells of a square, row or column, and only in these three cells. There may be other numbers in the same cells - they are removed


In the example, the numbers 4, 8 and 9 are hidden. There are no these numbers in the other cells of the column, which means we remove unnecessary candidates from the green cells.

hidden fours

Similarly with hidden triples, only 4 numbers in 4 cells.


In the example, four numbers 2, 3, 8, 9 in four cells (green) of one column form a hidden four, since these numbers are not in other cells of the column (orange). Extra candidates from green cells are removed.

This concludes the consideration of groups of numbers. For practice, try to solve the following crossword puzzles (without selection): Sudoku No. 13091, Sudoku No. 10710

X-wing and fish sword

These strange words are the names of two similar ways of eliminating Sudoku candidates.

X-wing

X-wing is considered for candidates of one number, consider 3:


There are only 2 triples in two rows (blue) and these triples lie on only two lines. This combination has only 2 triples solutions, and the other triples in the orange columns contradict this solution (check why), so the red triple candidates should be removed.

Similarly for candidates for 2 and columns.


In fact, the X-wing is quite common, but not so often the encounter with this situation promises the exclusion of extra numbers.

This is an advanced version of X-wing for three rows or columns:


We also consider 1 number, in the example it is 3. 3 columns (blue) contain triplets that belong to the same three rows.

Numbers may not be contained in all cells, but the intersection of three horizontal and three vertical lines is important to us. Either vertically or horizontally, there should be no numbers in all cells except green ones, in the example this is a vertical - columns. Then all the extra numbers in the lines should be removed so that 3 remains only at the intersections of the lines - in green cells.

Additional analytics

The relationship between hidden and naked groups.

And also the answer to the question: why are they not looking for hidden / naked fives, sixes, etc.?

Let's look at the following 2 examples:



This is one Sudoku where one numeric column is considered. 2 numbers 4 (marked in red) are eliminated in 2 different ways - using a hidden pair or using a bare pair.

Next example:



Another Sudoku, where in the same square there is both a bare pair and a hidden three, which remove the same numbers.


If you look at the examples of bare and hidden groups in the previous paragraphs, you will notice that with 4 free cells with a bare group, the remaining 2 cells will necessarily be a bare pair. With 8 free cells and a naked four, the remaining 4 cells will be a hidden four:

If we consider the relationship between bare and hidden groups, then we can find out that if there is a bare group in the remaining cells, there will necessarily be a hidden group and vice versa.

And from this we can conclude that if we have 9 cells free in a row, and among them there is definitely a naked six, then it will be easier to find a hidden triple than to look for a relationship between 6 cells. It is the same with the hidden and naked five - it is easier to find the naked / hidden four, so the fives are not even looked for.

And one more conclusion - it makes sense to look for groups of numbers only if there are at least eight free cells in a square, row or column, with a smaller number of cells, you can limit yourself to hidden and naked triples. And with five free cells or less, you can not look for triples - twos will be enough.

Final word

Here are the most famous methods for solving Sudoku, but when solving complex Sudoku, the use of these methods does not always lead to a complete solution. In any case, the selection method will always come to the rescue - save the Sudoku in a dead end, substitute any available number and try to solve the puzzle. If this substitution leads you to an impossible situation, then you need to boot up and remove the substitution number from the candidates.

Loading...Loading...