![]() The above one is very basic backtracking algorithm which is explained at many places. SecTopX, secTopY = 3 *(i//3), 3 *(j//3) #floored quotient should be used here. # finding the top left x,y co-ordinates of the section containing the i,j cell RowOk = all( for x in range(9)])ĬolumnOk = all( for x in range(9)]) A cell with value 0 indicates that it is not filled. It takes 9X9 grid partially filled with numbers. For each legal value, Go recursively and try to solve the grid.It's the bare minimum code which solves the problem. It uses simple backtracking algorithm to solve the puzzle.įor simplicity no input validations or fancy output is done. If you would like to try to solve this puzzle, download and print out this PDF Sudoku very hard puzzle #3.Here is my sudoku solver in python. Remove the two, and the puzzle can be quickly solved. Since branch cell (R2, C3) and cell (R4, C1) both share a 2, the Z, the 2 can be safely removed from consideration for the corner cell (R4, C3). Yet it will influence the corner cell (R4, C3). The branch cell YZ (R2, C3) is not in either row 1’s or row 4’s corner as you might expect. The right branch cell XZ is cell (R4C1) and contains the candidates (2,8). The left branch cell YZ is cell (R2C3) and holds the candidates (2,9). In this example, the stem cell XY is (R1C1), which contains the candidates (8,9). Sudoku XY-Wing (Example #2)Īt the left is a variation of the XY-Wing pattern that occurs in my experience more often than the first example described above. ![]() ![]() For more difficult puzzles, see my collection of printable free Sudoku puzzles. Congratulations on solving a very difficult Sudoku puzzle using Sudoku XY-Wing. You will be able to solve the puzzle quickly now by looking for naked singles. Since no other cell in the same region can possibly have a 1 or an 8, then cell (R4, C7), which has the candidates (1,7,8), must be a 7. Removing the 7 from the cell (R5, C8) circled in red leaves us with two cells with the naked pair (1,8).Following the “if-than-else” logic proves you can safely remove the “7” from cell R5C8.If R1C1 is a “3”, then R1C8 is a “7” therefore, you can remove the 7 from cell R5C8.If R1C1 is a “2”, then R5C1 is a “7”, therefore you can remove the 7 from cell R5C8.In the example shown, the “Z” candidate, a 7, can be removed from the cell (R5, C8) circled in red. You can safely remove the “Z” candidate from the cell(s) that share a relationship with the branch cells. The last branch cell XZ (R5C1) has the candidates (2,7). One of the branch cells YZ (R1C8) has the candidates (3,7). In the example shown above, the corner stem cell XY (R1C1) (highlighted in grey) has the pair (2,3). To illustrate this, the three cells contain the candidates XY (stem cell), YZ (branch cell), and XZ (branch cell). This results in a total of three unique candidates for the three cells in the form XY, YZ, and XZ. One candidate of the stem cell will be a shared candidate with the adjoining branch cell. There are two branch cells and one stem cell. Imagine two branches and a stem that form the letter “Y”. The XY-Wing pattern is made up of three cells that form a “Y” (with a little stretch of the imagination). If you have trouble getting to this position, follow the steps I have outlined in my article Sudoku Directions. If these terms are not familiar, read my article Sudoku Tips for an illustrative guide. You will need to solve naked singles, hidden singles, a naked pair, and two locked candidates first. You will need to partially solve the puzzle to reach the picture shown. If you would like to try to solve the first puzzle, download and print out this PDF Sudoku very hard puzzle #13 and follow along. In this article, I use two of my hand-crafted, very difficult puzzles that have a known XY-Wing pattern.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |