Update
This commit is contained in:
parent
d44127c798
commit
e8579f4b86
23 changed files with 1753 additions and 1711 deletions
22
sudoku.md
22
sudoku.md
|
@ -54,7 +54,25 @@ Humans almost exclusively use logical reasoning techniques to solve sudoku, whic
|
|||
- **scanning**: We take a look at some frequently appearing number in the grid and see which columns and rows they intersect which implies they cannot be placed in those columns and rows, possibly revealing the only possible location to place such number.
|
||||
- **single remaining candidate**: When there is only one number left to fill in any column, row or subgrid, it is always clear which one it is and can be safely placed.
|
||||
- **candidate sets**: A more advanced technique in which we create sets of possible candidate numbers for each square on the grid e.g. by writing tiny numbers in the top corners of the squares. We then apply various reasoning to reduce those sets, i.e. remove candidate numbers, until a single candidate remains for a certain square in which case we can fill in that number with certainty. This will further help us reason about candidates in other squares.
|
||||
- **inference chains and cycles**: Very advanced techniques, described e.g. at http://zitowolf.net/sudoku/strategy.html. { TBH no idea what this is. ~drummyfish }
|
||||
- **[set](set.md) equivalence properties**: Sudoku squares have some nice properties, it can e.g. easily be proven that some set of squares will always contain the same values as another set of squares -- this is quite easy to use, you just have to remember the rules that hold. See below.
|
||||
- **advanced techniques**: There are quite a lot more advanced and expert level techniques like X Wings, Alternating Inference Chains and many more, described e.g. at http://zitowolf.net/sudoku/strategy.html. { TBH no idea what this is. ~drummyfish }
|
||||
|
||||
Relatively recently (sometime in 2020s) there was a quite huge discovery/highlight of so called **Phistomefel ring** -- this is an area on the sudoku board that will always contain the same values as another area, which can greatly help in finding solutions (and also in generating sudokus). Consider the following patterns:
|
||||
|
||||
```
|
||||
_________________ _________________
|
||||
|B B .|. . .|. B B| |. . .|C C C|. . .|
|
||||
|B B .|. . .|. B B| |. . .|C C C|. . .|
|
||||
|._._A|A_A_A|A_._.| |D_D_D|._._.|D_D_D|
|
||||
|. . A|. . .|A . .| |D D D|. . .|D D D|
|
||||
|. . A|. . .|A . .| |. . .|C C C|. . .| ...
|
||||
|._._A|._._.|A_._.| |._._.|C_C_C|._._.|
|
||||
|. . A|A A A|A . .| |. . .|. . .|. . .|
|
||||
|B B .|. . .|. B B| |. . .|. . .|. . .|
|
||||
|B_B_.|._._.|._B_B| |._._.|._._.|._._.|
|
||||
```
|
||||
|
||||
On the left we see the Phistomefel ring -- the set of *A* squares (the ring) will always contain the same values as the set of *B* squares! (Check it on our example sudoku above.) That's it, it's pretty simple, and it's simple to prove too (quickly: consider set *S1* = row3 + row7 + 3x3square4 + 3x3square6, and *S2* = column1 + column2 + column8 + column9; it can be seen that *S1* and *S2* contain the same values; now remove from both sets their intersection -- we have removed the same values from both sets so they still contain the same values, set *S1* is now the Phistomefel ring, *S2* are the corners). A nice thing is that you can find more such relationship just using the simple idea of manipulating sets (the other example, values in sets *C* and *D* also have to be the same etc.).
|
||||
|
||||
For computers the traditional 9x9 sudoku is nowadays pretty easy to solve, however solving an NxN sudoku is an [NP complete](np_complete.md) problem, i.e. there most likely doesn't exist a "fast" algorithm for solving a generalized NxN sudoku, even though the common 9x9 variant can still be solved pretty quickly with today's computers by using some kind of "smart" [brute force](brute_force.md), for example [backtracking](backtracking.md) (or another state tree search) which [recursively](recursion.md) tries all possibilities and at any violation of the rules gets one step back to change the previous number. Besides this a computer can of course use all the reasoning techniques that humans use such as creating sets of possible values for each square and reducing those sets until only one possibility stays. The approach of reasoning and brute forcing may also be combined: first apply the former and when stuck fall back to the latter.
|
||||
|
||||
|
@ -64,6 +82,8 @@ For computers the traditional 9x9 sudoku is nowadays pretty easy to solve, howev
|
|||
|
||||
Generating sudoku puzzles is non-trivial. There are potentially many different [algorithms](algorithm.md) to do it, here we just foreshadow some common simple approaches.
|
||||
|
||||
Note that during generation of the sudoku you may utilize the knowledge of some inherent relationship between squares, e.g. the above mentioned Phistomefel ring.
|
||||
|
||||
Firstly we need to have implemented basic code for checking the validity of a grid and also some automatic solver, e.g. based on [backtracking](backtracking.md).
|
||||
|
||||
For generating a sudoku we usually start with a completely filled grid and keep removing numbers to leave only a few ones that become the initial clues. For this we have to know how to generate the solved grids. Dumb [brute force](brute_force.md) (i.e. generating completely random grids and testing their validity) won't work here as the probability of finding a valid grid this way is astronomically low (seems around 10^(-56)). What may work is to randomly fill a few squares so that they don't break the rules and then apply our solver to fill in the rest of the squares. Yet a simpler way may be to have a database of a few hand-made grids, then we pick on of them and apply some transformations that keep the validity of the grid which include swapping any two columns, swapping any two rows, [tansposing](transposition.md), flipping the grid, rotating it 90 degrees or swapping any two digits (e.g. swap all 7s with all 9s).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue