sudoku theory

Upload: ron-bryant

Post on 06-Apr-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Sudoku Theory

    1/13

    SudokuIntroduction

    Sudoku

    History

    Strategy

    Advanced

    Theory

    TypesGuides

    Guessing

    Symmetry

    News

    Donate

    Dragon

    Daily

    Online

    Forum

    Help

    Manual

    Books

    Site Map

    Sudoku

    udoku is all about permutations, but permutations with an extra twist of logic. To look into the

    theory behind Sudoku you need to first look into permutations.

    A permutation is just a particular ordering of symbols. In Sudoku it is insisted that there is only oneoccurrence of each symbol (or number) in each group (row, column or region).

    So for two symbols there are only two possible orders {1;2} and {2;1} with three there are six {1;2;3},{1;3;2}, {2;1;3}, {2;3;1}, {3;1;2} and {3;2;1} possible orders and for four there are 24 permutations ofthe four symbols. The number of permutations is the Factorial of the number of symbols in theset, as each time an extra element is added to a set of size 'n' that element multiplies up the numberof arrangements of the previous set size. So for the standard Sudoku set size of 9 we have 9 factorial(represented in maths as 9!) or 9x8x7x6x5x4x3x2x1 possible permutations which works out as362,880 possible ways of ordering the nine symbols in a row, column or region.

    Properties of permutations

    Permutations do not look at all exciting; but from it you can create other permutations by doing oneof the following:

    Swap the symbols consistentlyIn a permutation you can always swap all occurrences of one symbol for another as long as the swapis done systematically and in reverse too. If you swap 4 with 1 then the 1 must be swapped to a 4(e.g. 4;2;3;1 would become 1;2;3;4). Several or all symbols can be swapped in this way. The resultwill always be a valid permutation.

    Here is a 4x4 puzzle with 1;2;3 swapped for 3;1;2 respectively; they are both valid 'Sudokus'.

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    1 of 13 2/16/2012 9:47 PM

  • 8/3/2019 Sudoku Theory

    2/13

    Solver

    Download Sudoku

    Dragon for a free

    23 day trial on

    your PC. It has all

    the features you

    need to solve

    puzzles whether

    you are new to

    Sudoku or an

    expert.

    Today's

    Dragon Tip

    Learn the basicsLook through ourrange of easy tofollow guides topuzzle solvingstrategies, makesure you areup-to-speed on

    all the main waysof solving thepuzzle.Read More

    Shifting the orderPermutations are by their nature just an ordering so you can swap the order however much you likeand the result is also a permutation. For example you can shift the symbol '8' from the start to theend so (8;4;5;6;1;2;7;9;3) becomes (4;5;6;1;2;7;9;3;8) or swap each element with its neighbor inpairs so (8;4;5;6;1;2;7;9;3) becomes (4;8;6;5;2;1;9;7;3).

    Here is a 4x4 puzzle with the bottom two rows swapped, they are both valid 'Sudokus'.

    The original related puzzle ofMagic squares has the property that all the numbers in rows andcolumns add up to the same number.

    This is also a property of permutations, if you add up the individual numbers in the set that makeup the permutation then this will always give the same result. This is because addition is Associative

    , it does not matter in which order you add up the numbers, you always end up with the sameresult ((5+1)+2) = (5+(1+2)). The same is true of multiplication but it is not true of all the simplearithmetic operations; as both subtraction and division give different results depending on the orderthat the operations are carried out, e.g. (4 / 3) / 2 is not the same as 4 / (3 / 2).

    If we add up all the numbers in a completed 9x9 Sudoku row, column or region the answer is

    always the same: 45, and if they are multiplied together the answer is always 362,880 (this is our 9'factorial' or 9!)

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    2 of 13 2/16/2012 9:47 PM

  • 8/3/2019 Sudoku Theory

    3/13

    This is starting to look useful because if we had a number missing it can be deduced which one it is.For example, if there is one number missing and the sum of the other numbers is 40 the missingnumber must be a '5' to make up the required group total of 45. This does not work in general as,for example, if two numbers are missing and the total is 38, it can't be directly deduced what the

    numbers are, it could be any two numbers that add up to 7 (either 2 and 5; or 1 and 6; or 3 and 4).Similarly with multiplication, the value of missing number this can be deduced by multiplyingtogether all the numbers that are there and dividing this product into 362,880. For example if thegroup is 8;4;6;1;2;5;9;3 the product is 51,840 so dividing this into 362,880 we get the answer '7' asthe missing number. Unfortunately, just like addition we can't use this scheme to determine whichof two or more numbers are missing. There is more than one choice of numbers that give the sameanswer.

    Here are the factorials from 1 to 9 (9!).

    Before getting any further into any more analysis, let's simplify by using the 4x4 Sudoku grid ratherthan 9x9 just to reduce the number of options. In the 4x4 grid, the rules are just the same but thereare only four numbers (1, 2, 3 and 4) in each row, column and region. So a permutation of all thenumbers must add up to 10 and the product of all the numbers is 24 (4! factorial). [Sudoku Dragonsupports ten different puzzle sizes including the 4x4 and 16x16 sized puzzles.]

    The problem with deducing missing numbers does not arise if we use a form ofGdel numbers .Here we don't just multiply the Sudoku numbers together we use the corresponding prime number.So for a '1' we use the first prime number '2', for '2' use the second prime '3'; for '3' use '5'; for '4'use '7' and so on.

    All Sudoku groups in the 4x4 grid must now multiply up to give a product of 2x3x5x7 = 210 ratherthan 24. If a Sudoku 4x4 group is 2;;3;; with two missing numbers we convert these to thecorresponding prime and multiply them together 3 x 5 giving 15. Now 210 / 15 = 14. So the two

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    3 of 13 2/16/2012 9:47 PM

  • 8/3/2019 Sudoku Theory

    4/13

    Sudoku Theory http://www sudokudragon com/sudokutheory htm

  • 8/3/2019 Sudoku Theory

    5/13

    1111 to confirm that each of the four symbols has occurred once in all four positions in the group.This can then be used to find missing numbers, a group with 2;;3;; would be translated as0010;;0100;; logically ored together gives 0110, so we can now tell at a glance that it is a '4' and a '1'that are the missing numbers as they correspond with the missing symbols represented by '0's. Sorather than using Gdel numbers the same can be applied to Sudoku much more easily using

    boolean 'yes/no' questions.

    Actions and Operations

    There is another way of looking at permutations and symbols. You can think of the contents not assymbols but as operations to perform. A permutation is just saying that you need to perform a set ofoperations only once but in any order. To make this more everyday consider four operations : gettingdressed; brushing hair; collecting the post and eating breakfast. We might do each of these once

    every morning, and they can be done in any order. If you think of these as a permutation withnumbers 3;2;4;1 might represent collect post; brush hair; eat breakfast; get dressed. That'sestablished the idea of thinking of a permutation as a sequence of operations done in time orderrather than symbols. Looking at this in a simpler, more mathematical sense we could treat eachsymbol as a move along a vector. An 'operation' is in terms of moving a certain amount in a certaindirection. So we could use '1' as move 2 units N ; '2' as move 2 units S; '3' as move W 2 units and '4'move E 2 units. These are chosen so that the end result of completing all these steps takes you backto where you started. This is important as it makes the sequence of operations into a mathematical

    concept known as a 'ring' in group theory . Other examples of these sorts of patterns are squaredances where after a number of moves, twists and turns you end up where you started. Othervectors could have been chosen. Just like addition the moves can be done in any order to achievethe same end position. This approach allows missing moves to be deduced by just combining theknown moves and working out how to get back to the original point. Applied to Sudoku this can beused to work out which numbers are missing.

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    5 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www sudokudragon com/sudokutheory htm

  • 8/3/2019 Sudoku Theory

    6/13

    If Sudoku were just a matter of single groups of symbols then it wouldn't be much of a challenge.The complexity comes from applying the restriction of a single group into a two dimensional grid.There are then three constraints on each squares: it must be unique to the row; column and region.

    Sudoku Possibility Analysis

    Apart from the simplest cases (where only one choice is available) solving a Sudoku puzzle involvesanalysing permutations. Each unsolved square can have one or more possibilities. Each unusedsymbol must be possible in one or more squares in a group.

    If we look at a Sudoku group on its own then all the unused symbols can occur in any of theunsolved squares. However taking the other groups that share squares with this group reduces the

    number of possibilities. So for a row having 7; ; ;6;3; ; ;2;5 the four missing numbers are 1;4;8;9these could on their own occur in any permutation within the squares. Other groups (columns,regions) may, for example. reduce the choice down to {1;4;8}, {1;8;9}, {4;8} and {1;4;8;9} for the fourempty squares. Each of these is a subset of the missing numbers (1;4;8;9) and it is the pattern ofthese subsets that are used to deduce additional constraints on the possible content of the squares.For example, if the possibility subsets were {1;8} {1;8} {4;8;9} and {4;9} then {1;8} is an example of a'naked twin', there are two squares with these two possibilities and this means that the '1' must goin one of the two places and '8' in the other place. Therefore the square with {4;8;9} as possibilities

    can be safely restricted down to {4;9} as the '8' can't occur there. This is the simplest case of howanalysis of possibilities can be helpful in reducing the options. By using the knowledge that a symbolmay occur only in a subset of the squares we cannot deduce where exactly it can go but deducewhere it cannot go.

    General possibility rule

    The 'naked twin' rule is just the simplest example of a general rule for Sudoku possibilities. The ruleis that if there are 'n' symbols and all possibilities for these symbols are located in a subset of 'n'squares within a group then we have a sub-group of possibilities. Apart from the twin example thereis the 'chain'. If the possibilities were {1;4} {4;8} {8;1} and {1;4;9} then the first three form a chain of

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    6 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    7/13

    the symbols {1;4;8} and preclude the occurrence of these symbols in the last square, in this case thelast square becomes a 'single possibility' square as it must be '9'. A chain is a closed loop of symbolsthat imply that the symbols must occur only in this group but it can not be determined whereprecisely the numbers go. In the case of {1;4} and {4;1} in a group this is just saying the allocation iseither {1} and {4} or {4} and {1} so the 1 and 4 can not occur anywhere else. The same logic applies to

    3 or more symbols it is not limited to just two. If we had {1;4;9} {1;4;9} {1;4;9} and {4;8} then thethree squares form a triplet of {1;4;9} and the other square must be '8' as 4 must be allocated in thetriplet.

    In this example taken from a 9x9 grid, one region has two naked twins {4;5} in the top row A. Usingthe twin rule 4 can not occur in the four other unallocated squares and 5 in three of the remainingsquares. This makes it a very useful rule.

    Beyond the linear dimension

    Much of this analysis so far has looked at one Sudoku group in isolation. Each square is a memberof three groups (row; column and region) and the rules for one group apply equally to the othergroups. So if a column requires that {1;4;9} are the possibilities for a square in the column and therow it is in gives {2;4;9} as possibilities for that square then the combined constraint for the square

    is just 4 or 9 {4;9}. If the region gives possibilities {3;4;5} then that would leaves {4} as the onlypossibility that meets the requirements of the row; column and region. The knowledge that a {4}must go in the square can be fed back into the constraints for the three groups as it precludes {4}being a possibility anywhere else in these groups as well.

    The usefulness does not end there. Some of the constraints are 'indirect' meaning that theimplication for one square will limit what can go in another square, but because of the sharedgroups it is in. The simplest example of this is the X-Wing. Here four groups are logically inter-linkedto form a 'box'. If the possibilities form a particular pattern then the corners of the box must be inone of only two configurations. The Sudoku rules are applying a two-dimensional constraintinvolving four groups (two rows and two columns) because of the X-Wing. This can become even

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

    7 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    8/13

    more complicated as even more groups can become involved. These cyclic dependencies result fromthe ways that squares are connected via groups into interconnected grids. Both humans andcomputers struggle to find these interdependencies between possibilities. Luckily most Sudokupuzzles can be solved without needing to work them out.

    Finding patterns within these permutation subsets is definitely a 'hard' problem. This is not just forhumans, it is just as tough for computers too. Pattern matching problems like Sudoku belong to theclass of the difficult problems to solve :The NP complete class . Any analysis has to look through allthe possible combinations; it cannot do it as a single linear scan of the permutations. To spot a 'twin'

    a computer needs to look through all possible combinations of two squares in a group. The timetaken to solve NP complete problems does not grow linearly with problem size it grows exponentially.If it takes 2 seconds to solve a problem of size '3' it will take much more than 4 seconds to solve aproblem of size '6'. There is no simple 'trick' that a human or computer can use to solve Sudokupuzzles in general, if you find a way you will become a multi-millionaire.

    The simplest algorithm is the trial and error method which checks all the possibilities in turnwithout looking for rules such as excluded possibilities or only square. This can take a very long time

    to do as there just so many to check - the crudest algorithm would work through something like 10to the power 47 combinations (that's 10 with 47 noughts after it).

    What is the most difficult Sudoku puzzle ever discovered? To be genuinely hard to solve a puzzlemust reveal the minimum number of squares and still have a unique solution. There are manyexamples of puzzles that are not 'solvable' without having to make a guess on the content of thesquare. This is difficult to determine as there are a number ofadvanced solution strategies available

    that need to be tried before being certain that this is the case. Here is an example of a truly difficultstandard puzzle that you might like to try to solve. It is not symmetric and so can be considered nota valid Sudoku. The asymmetry can make puzzles harder to solve. The puzzle has only 21 revealed

    y p g y

    8 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    9/13

    squares.

    To download this puzzle and see it in Sudoku Dragon click here...

    Many puzzlers reckon that having a large empty space in the middle creates some very tricky

    puzzles. If so then surely this must qualify as one of the hardest possible puzzles to solve. It has just22 revealed squares. It is reckoned that the hardest possible Sudokus have 17 or 18 'given' orinitially revealed squares.

    To download this puzzle and see it in Sudoku Dragon click here...

    y p g y

    9 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    10/13

    The 4x4 PuzzleThere is nothing all that special about 9x9 Sudoku puzzles, it just happens to make an interestingSudoku puzzle that can be solved in a reasonable time. However it is possible to choose a smaller orlarger size of grid.

    With 4x4 there are only 16 squares in total and it is impossible to create a difficult puzzle. Theminimum number of squares that can be revealed and still produce a solvable puzzle is four. I havenever seen a 4x4 with only 3 initial squares revealed - this may be provable to be an impossiblestarting arrangement.

    10 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    11/13

    The 16x16 Puzzle

    Moving to larger than the regular 9x9 puzzle size introduces nothing new other than morepossibilities to work through. All the strategies you might use for solving 9x9 can be adapted to thelarger 16x16 grid. For example the 'two out of three' strategy becomes the 'three out of four'strategy. You can still use all the basic strategies : only choice, single possibility, only square,excluded hidden twins, naked twins, excluded sub-group, X-Wing and all the advanced strategies. Itbecomes much harder for mere humans to solve when there are 16 rather than 9 numbers/symbolsto reason about. But with practice these grids can become quite straightforward to solve too.

    11 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    12/13

    Larger Sudoku Puzzles

    There is no theoretical limit on the size of a Sudoku puzzle. The rules are generic and bymathematical induction it can be shown that they just grow and grow. Keeping to a squarearrangement the number just goes up in squares : 16x16; 25x25; 36x36 (over a thousand squares tocomplete); 49x49; 81x81; 100x100 (10,000 squares in the puzzle).

    Rectangular Puzzles

    A set of same sized rectangles can be arranged into a square puzzle grid. One rectangular Sudoku ismade up of 3x5 blocks arranged as three blocks wide and five blocks deep giving 15 regions in all.

    The same can be done with many other sizes (e.g. six 2x3 blocks), in fact the only grid sizes thatcan't be used are those that are prime numbers and so can't be divided up into a rectangular block(e.g. a 5x5 puzzle can not be subdivided in any different way). Sudoku Dragon supports 2x3, 2x4,3x5, 3x5, 4x5, 2x5 and 2x7 rectangular block puzzles giving puzzle sizes of 6, 8, 15, 20, 10 and 14respectively.

    Please refer to ourTheme and Variations page for more strange and interesting forms of Sudoku.

    Here is an example of a 14x14 grid made up two stacks of 2x7 squares. The symbols used are 0 to 9

    and A to D

    The Smallest Sudoku Puzzle

    12 of 13 2/16/2012 9:47 PM

    Sudoku Theory http://www.sudokudragon.com/sudokutheory.htm

  • 8/3/2019 Sudoku Theory

    13/13

    For the pure mathematicians amongst you, it may be interesting to note that from a pedantic pointof view 4x4 is not the simplest size of Sudoku puzzle. If instead of all groups having 4 squares in itwe have just 'one' square then, even though it is rather academic, the 1x1 sudoku puzzle has 1 rowand 1 column with 1 symbol occurring just once in each row and column. There is only one regionwith 1 square in it. So there is only one Sudoku puzzle of size 1 and the solution is 1.Mathematicians may appreciate the symmetry as it shows that the Sudoku rules are general for anygroup size including 1 upwards. It just happens that 1 is a seriously simple puzzle to solve!

    See also:Sudoku Solvers A range of mathematical puzzles and solvers.

    Give our SudokuDragon puzzle solver a free 23 day trial by visiting our download page.All the main Sudoku strategies have clear, easy to follow guides. It can help you quicklyidentify square possibilities and exclude the ones that actually are impossible.

    ny comments on this page ? Click here to contribute

    Copyright 2005-2012 Sudoku Dragon

    13 of 13 2/16/2012 9:47 PM