🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 152 (from laksa099)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
18 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.6 months ago (distributed domain, exempt)
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://en.wikipedia.org/wiki/Sudoku_solving_algorithms
Last Crawled2026-03-20 09:32:49 (18 days ago)
First Indexed2015-07-20 03:57:26 (10 years ago)
HTTP Status Code200
Meta TitleSudoku solving algorithms - Wikipedia
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
From Wikipedia, the free encyclopedia A typical Sudoku puzzle A standard Sudoku contains 81 cells, in a 9×9 grid, and has 9 boxes, each box being the intersection of the first, middle, or last 3 rows, and the first, middle, or last 3 columns. Each cell may contain a number from one to nine, and each number can only occur once in each row, column, and box. A Sudoku starts with some cells containing numbers ( clues ), and the goal is to solve the remaining cells. Proper Sudokus have one solution. [ 1 ] Players and investigators use a wide range of computer algorithms to solve Sudokus, study their properties, and make new puzzles, including Sudokus with interesting symmetries and other properties. There are several computer algorithms that will solve 9×9 puzzles ( n = 9) in fractions of a second, but combinatorial explosion occurs as n increases, creating limits to the properties of Sudokus that can be constructed, analyzed, and solved as n increases. A Sudoku (top) being solved by backtracking . Each cell is tested for a valid number, moving "back" when there is a violation, and moving forward again until the puzzle is solved. A Sudoku designed to work against the brute force algorithm [ 2 ] Some hobbyists have developed computer programs that will solve Sudoku puzzles using a backtracking algorithm, which is a type of brute force search . [ 3 ] Backtracking is a depth-first search (in contrast to a breadth-first search ), because it will completely explore one branch to a possible solution before moving to another branch. Although it has been established that approximately 5.96 x 10 26 final grids exist, a brute force algorithm can be a practical method to solve Sudoku puzzles. A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid. [ 4 ] [ 5 ] [ 6 ] [ 7 ] Briefly, a program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell and places a "1" in that cell. When checking for violations, if it is discovered that the "1" is not allowed, the value is advanced to "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. This is repeated until the allowed value in the last (81st) cell is discovered. The animation shows how a Sudoku is solved with this method. The puzzle's clues (red numbers) remain fixed while the algorithm tests each unsolved cell with a possible solution. Notice that the algorithm may discard all the previously tested values if it finds the existing set does not fulfill the constraints of the Sudoku. Advantages of this method are: A solution is guaranteed (as long as the puzzle is valid). Solving time is mostly unrelated to degree of difficulty . [ dubious – discuss ] The algorithm (and therefore the program code) is simpler than other algorithms, especially compared to strong algorithms that ensure a solution to the most difficult puzzles. The disadvantage of this method is that the solving time may be slow compared to algorithms modeled after deductive methods. One programmer reported that such an algorithm may typically require as few as 15,000 cycles, or as many as 900,000 cycles to solve a Sudoku, each cycle being the change in position of a "pointer" as it moves through the cells of a Sudoku. [ 8 ] [ 9 ] A different approach which also uses backtracking, draws from the fact that in the solution to a standard sudoku the distribution for every individual symbol (value) must be one of only 46656 patterns. In manual sudoku solving this technique is referred to as pattern overlay or using templates and is confined to filling in the last values only. A library with all the possible patterns may get loaded or created at program start. Then every given symbol gets assigned a filtered set with those patterns, which are in accordance with the given clues. In the last step, the actual backtracking part, patterns from these sets are tried to be combined or overlaid in a non-conflicting way until the one permissible combination is hit upon. The Implementation is exceptionally easy when using bit vectors, because for all the tests only bit-wise logical operations are needed, instead of any nested iterations across rows and columns. Significant optimization can be achieved by reducing the sets of patterns even further during filtering. By testing every questionable pattern against all the reduced sets that were already accepted for the other symbols the total number of patterns left for backtracking is greatly diminished. And as with all sudoku brute-force techniques, run time can be vastly reduced by first applying some of the most simple solving practices which may fill in some 'easy' values. A Sudoku can be constructed to work against backtracking. Assuming the solver works from top to bottom (as in the animation), a puzzle with few clues (17), no clues in the top row, and has a solution "987654321" for the first row, would work in opposition to the algorithm. Thus the program would spend significant time "counting" upward before it arrives at the grid which satisfies the puzzle. In one case, a programmer found a brute force program required six hours to arrive at the solution for such a Sudoku (albeit using a 2008-era computer). Such a Sudoku can be solved nowadays in less than 1 second using an exhaustive search routine and faster processors. [ 10 ] p:25 Stochastic search / optimization methods [ edit ] Sudoku can be solved using stochastic (random-based) algorithms. [ 11 ] [ 12 ] An example of this method is to: Randomly assign numbers to the blank cells in the grid. Calculate the number of errors. "Shuffle" the inserted numbers until the number of mistakes is reduced to zero. A solution to the puzzle is then found. Approaches for shuffling the numbers include simulated annealing , genetic algorithm and tabu search . Stochastic-based algorithms are known to be fast, though perhaps not as fast as deductive techniques. Unlike the latter however, optimisation algorithms do not necessarily require problems to be logic-solvable, giving them the potential to solve a wider range of problems. Algorithms designed for graph colouring are also known to perform well with Sudokus. [ 13 ] It is also possible to express a Sudoku as an integer linear programming problem. Such approaches get close to a solution quickly, and can then use branching towards the end. The simplex algorithm is able to solve proper Sudokus, indicating if the Sudoku is not valid (no solution). If there is more than one solution (non-proper Sudokus) the simplex algorithm will generally yield a solution with fractional amounts of more than one digit in some squares. However, for proper Sudokus, linear programming presolve techniques alone will deduce the solution without any need for simplex iterations. The logical rules used by presolve techniques for the reduction of LP problems include the set of logical rules used by humans to solve Sudokus. Constraint programming [ edit ] A Sudoku may also be modelled as a constraint satisfaction problem . In his paper Sudoku as a Constraint Problem , [ 14 ] Helmut Simonis describes many reasoning algorithms based on constraints which can be applied to model and solve problems. Some constraint solvers include a method to model and solve Sudokus, and a program may require fewer than 100 lines of code to solve a simple Sudoku. [ 15 ] [ 16 ] If the code employs a strong reasoning algorithm, incorporating backtracking is only needed for the most difficult Sudokus. An algorithm combining a constraint-model-based algorithm with backtracking would have the advantage of fast solving time – of the order of a few milliseconds [ 17 ] – and the ability to solve all sudokus. [ 5 ] Sudoku puzzles may be described as an exact cover problem, or more precisely, an exact hitting set problem. This allows for an elegant description of the problem and an efficient solution. Modelling Sudoku as an exact cover problem and using an algorithm such as Knuth's Algorithm X and his Dancing Links technique "is the method of choice for rapid finding [measured in microseconds] of all possible solutions to Sudoku puzzles." [ 18 ] An alternative approach is the use of Gauss elimination in combination with column and row striking. Relations and residuals [ edit ] Let Q be the 9x9 Sudoku matrix, N = {1, 2, 3, 4, 5, 6, 7, 8, 9}, and X represent a generic row, column, or block. N supplies symbols for filling Q as well as the index set for the 9 elements of any X . The given elements q in Q represent a univalent relation from Q to N . The solution R is a total relation and hence a function . Sudoku rules require that the restriction of R to X is a bijection , so any partial solution C , restricted to an X , is a partial permutation of N . Let T = { X  : X is a row, column, or block of Q }, so T has 27 elements. An arrangement is either a partial permutation or a permutation on N . Let Z be the set of all arrangements on N . A partial solution C can be reformulated to include the rules as a composition of relations A (one-to-three) and B requiring compatible arrangements: Solution of the puzzle, suggestions for new q to enter Q , come from prohibited arrangements , the complement of C in Q x Z : useful tools in the calculus of relations are residuals : maps T to Z , and maps Q to T . Sudoku Mathematics of Sudoku Combinatorial explosion (with summary of grid count of Sudoku compared to Latin squares) Glossary of Sudoku ^ Mahmood, Yasser (2009). "More about Sudoku" . Cornell University . Retrieved 2024-11-26 . ^ "Star Burst - Polar Graph" A polar chart showing a solution path for a Sudoku (Star Burst) using an exhaustive search routine and comment about 17-clue Sudoku. ^ http://intelligence.worldofcomputing/brute-force-search Brute Force Search, December 14th, 2009. ^ "Backtracking - Set 7 (Sudoku)" . GeeksforGeeks . Archived from the original on 2016-08-28 . Retrieved 24 December 2016 . ^ a b Norvig, Peter. "Solving Every Sudoku Puzzle" . Peter Norvig (personal website) . Retrieved 24 December 2016 . ^ "Chart of Cells Visited for Solution" A chart showing a solution path to a difficult Sudoku. ^ Zelenski, Julie (July 16, 2008). Lecture 11 | Programming Abstractions (Stanford) . Stanford Computer Science Department. ^ "Star Burst Leo - Polar Graph" A polar chart showing a solution path for a Sudoku (Star Burst Leo) using an exhaustive search routine. ^ "Chart of Cells Visited for Solution" A chart showing a solution path for a difficult Sudoku using an exhaustive search routine. ^ McGuire, Gary; Tugemann, Bastian; Civario, Gilles (2012). "A Game of Sudoku" (PDF) . ResearchGate : 25 . Retrieved 2024-11-27 . ^ Lewis, R (2007) Metaheuristics Can Solve Sudoku Puzzles Journal of Heuristics, vol. 13 (4), pp 387-401. ^ Perez, Meir and Marwala, Tshilidzi (2008) Stochastic Optimization Approaches for Solving Sudoku arXiv:0805.0697. ^ Lewis, R. A Guide to Graph Colouring: Algorithms and Applications . Springer International Publishers, 2015. ^ Simonis, Helmut (2005). "Sudoku as a Constraint Problem". CiteSeerX   10.1.1.88.2964 . paper presented at the Eleventh International Conference on Principles and Practice of Constraint Programming ^ Multiple Authors. "Java Constraint Programming solver" (Java) . JaCoP . Krzysztof Kuchcinski & Radoslaw Szymanek . Retrieved 8 December 2016 . ^ Rhollor. "Sudokusolver" (C++) . GitHub . Rhollor . Retrieved 8 December 2016 . ^ "Sudoku - Rosetta Code" . rosettacode.org . Retrieved 2021-11-30 . ^ Hanson, Robert M. (16 August 2022). "Exact Cover Matrix" . http://diuf.unifr.ch/pai/people/juillera/Sudoku/Sudoku.html Sudoku Explainer by Nicolas Juillerat (Popular for rating Sudokus in general) Archived 2013-11-12 at the Wayback Machine A Pencil-and-Paper Algorithm for Solving Sudoku Puzzles
Markdown
[Jump to content](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#bodyContent) Main menu Main menu move to sidebar hide Navigation - [Main page](https://en.wikipedia.org/wiki/Main_Page "Visit the main page [z]") - [Contents](https://en.wikipedia.org/wiki/Wikipedia:Contents "Guides to browsing Wikipedia") - [Current events](https://en.wikipedia.org/wiki/Portal:Current_events "Articles related to current events") - [Random article](https://en.wikipedia.org/wiki/Special:Random "Visit a randomly selected article [x]") - [About Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:About "Learn about Wikipedia and how it works") - [Contact us](https://en.wikipedia.org/wiki/Wikipedia:Contact_us "How to contact Wikipedia") Contribute - [Help](https://en.wikipedia.org/wiki/Help:Contents "Guidance on how to use and edit Wikipedia") - [Learn to edit](https://en.wikipedia.org/wiki/Help:Introduction "Learn how to edit Wikipedia") - [Community portal](https://en.wikipedia.org/wiki/Wikipedia:Community_portal "The hub for editors") - [Recent changes](https://en.wikipedia.org/wiki/Special:RecentChanges "A list of recent changes to Wikipedia [r]") - [Upload file](https://en.wikipedia.org/wiki/Wikipedia:File_upload_wizard "Add images or other media for use on Wikipedia") - [Special pages](https://en.wikipedia.org/wiki/Special:SpecialPages "A list of all special pages [q]") [![](https://en.wikipedia.org/static/images/icons/enwiki-25.svg) ![Wikipedia](https://en.wikipedia.org/static/images/mobile/copyright/wikipedia-wordmark-en-25.svg) ![The Free Encyclopedia](https://en.wikipedia.org/static/images/mobile/copyright/wikipedia-tagline-en-25.svg)](https://en.wikipedia.org/wiki/Main_Page) [Search](https://en.wikipedia.org/wiki/Special:Search "Search Wikipedia [f]") Appearance - [Donate](https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=en.wikipedia.org&uselang=en) - [Create account](https://en.wikipedia.org/w/index.php?title=Special:CreateAccount&returnto=Sudoku+solving+algorithms "You are encouraged to create an account and log in; however, it is not mandatory") - [Log in](https://en.wikipedia.org/w/index.php?title=Special:UserLogin&returnto=Sudoku+solving+algorithms "You're encouraged to log in; however, it's not mandatory. [o]") Personal tools - [Donate](https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=en.wikipedia.org&uselang=en) - [Create account](https://en.wikipedia.org/w/index.php?title=Special:CreateAccount&returnto=Sudoku+solving+algorithms "You are encouraged to create an account and log in; however, it is not mandatory") - [Log in](https://en.wikipedia.org/w/index.php?title=Special:UserLogin&returnto=Sudoku+solving+algorithms "You're encouraged to log in; however, it's not mandatory. [o]") ## Contents move to sidebar hide - [(Top)](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms) - [1 Techniques](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Techniques) Toggle Techniques subsection - [1\.1 Backtracking](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Backtracking) - [1\.2 Stochastic search / optimization methods](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Stochastic_search_/_optimization_methods) - [1\.3 Constraint programming](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Constraint_programming) - [1\.4 Exact cover](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Exact_cover) - [1\.5 Relations and residuals](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Relations_and_residuals) - [2 See also](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#See_also) - [3 References](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#References) - [4 External links](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#External_links) Toggle the table of contents # Sudoku solving algorithms 5 languages - [Español](https://es.wikipedia.org/wiki/Algoritmos_para_la_resoluci%C3%B3n_de_sudokus "Algoritmos para la resolución de sudokus – Spanish") - [فارسی](https://fa.wikipedia.org/wiki/%D8%A7%D9%84%DA%AF%D9%88%D8%B1%DB%8C%D8%AA%D9%85%E2%80%8C%D9%87%D8%A7%DB%8C_%D8%AD%D9%84_%D8%B3%D9%88%D8%AF%D9%88%DA%A9%D9%88 "الگوریتم‌های حل سودوکو – Persian") - [Français](https://fr.wikipedia.org/wiki/Algorithmes_de_r%C3%A9solution_des_sudokus "Algorithmes de résolution des sudokus – French") - [Português](https://pt.wikipedia.org/wiki/Algoritmo_de_sudoku "Algoritmo de sudoku – Portuguese") - [Српски / srpski](https://sr.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D0%B8_%D0%B7%D0%B0_%D1%80%D0%B5%D1%88%D0%B0%D0%B2%D0%B0%D1%9A%D0%B5_%D1%81%D1%83%D0%B4%D0%BE%D0%BA%D1%83%D0%B0 "Алгоритми за решавање судокуа – Serbian") [Edit links](https://www.wikidata.org/wiki/Special:EntityPage/Q2756506#sitelinks-wikipedia "Edit interlanguage links") - [Article](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms "View the content page [c]") - [Talk](https://en.wikipedia.org/wiki/Talk:Sudoku_solving_algorithms "Discuss improvements to the content page [t]") English - [Read](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms) - [Edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit "Edit this page [e]") - [View history](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=history "Past revisions of this page [h]") Tools Tools move to sidebar hide Actions - [Read](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms) - [Edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit "Edit this page [e]") - [View history](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=history) General - [What links here](https://en.wikipedia.org/wiki/Special:WhatLinksHere/Sudoku_solving_algorithms "List of all English Wikipedia pages containing links to this page [j]") - [Related changes](https://en.wikipedia.org/wiki/Special:RecentChangesLinked/Sudoku_solving_algorithms "Recent changes in pages linked from this page [k]") - [Upload file](https://en.wikipedia.org/wiki/Wikipedia:File_Upload_Wizard "Upload files [u]") - [Permanent link](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&oldid=1316656345 "Permanent link to this revision of this page") - [Page information](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=info "More information about this page") - [Cite this page](https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=Sudoku_solving_algorithms&id=1316656345&wpFormIdentifier=titleform "Information on how to cite this page") - [Get shortened URL](https://en.wikipedia.org/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSudoku_solving_algorithms) Print/export - [Download as PDF](https://en.wikipedia.org/w/index.php?title=Special:DownloadAsPdf&page=Sudoku_solving_algorithms&action=show-download-screen "Download this page as a PDF file") - [Printable version](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&printable=yes "Printable version of this page [p]") In other projects - [Wikidata item](https://www.wikidata.org/wiki/Special:EntityPage/Q2756506 "Structured data on this page hosted by Wikidata [g]") Appearance move to sidebar hide From Wikipedia, the free encyclopedia Algorithms to complete a sudoku [![A typical Sudoku puzzle, a 9x9 grid with several numbers missing](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg/330px-Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg.png)](https://en.wikipedia.org/wiki/File:Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg) A typical Sudoku puzzle A standard [Sudoku](https://en.wikipedia.org/wiki/Sudoku "Sudoku") contains 81 cells, in a 9×9 grid, and has 9 boxes, each box being the intersection of the first, middle, or last 3 rows, and the first, middle, or last 3 columns. Each cell may contain a number from one to nine, and each number can only occur once in each row, column, and box. A Sudoku starts with some cells containing numbers (*clues*), and the goal is to solve the remaining cells. Proper Sudokus have one solution.[\[1\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-1) Players and investigators use a wide range of computer algorithms to solve Sudokus, study their properties, and make new puzzles, including Sudokus with interesting symmetries and other properties. There are several computer algorithms that will solve 9×9 puzzles (n = 9) in fractions of a second, but [combinatorial explosion](https://en.wikipedia.org/wiki/Combinatorial_explosion "Combinatorial explosion") occurs as n increases, creating limits to the properties of Sudokus that can be constructed, analyzed, and solved as n increases. ## Techniques \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=1 "Edit section: Techniques")\] ### Backtracking \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=2 "Edit section: Backtracking")\] [![](https://upload.wikimedia.org/wikipedia/commons/8/8c/Sudoku_solved_by_bactracking.gif)](https://en.wikipedia.org/wiki/File:Sudoku_solved_by_bactracking.gif) A Sudoku (top) being solved by **backtracking**. Each cell is tested for a valid number, moving "back" when there is a violation, and moving forward again until the puzzle is solved. [![](https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Sudoku_puzzle_hard_for_brute_force.svg/330px-Sudoku_puzzle_hard_for_brute_force.svg.png)](https://en.wikipedia.org/wiki/File:Sudoku_puzzle_hard_for_brute_force.svg) A Sudoku designed to work against the brute force algorithm[\[2\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-difficult_17_clue-2) Main article: [Brute-force search](https://en.wikipedia.org/wiki/Brute-force_search "Brute-force search") Some hobbyists have developed computer programs that will solve Sudoku puzzles using a [backtracking](https://en.wikipedia.org/wiki/Backtracking "Backtracking") algorithm, which is a type of [brute force search](https://en.wikipedia.org/wiki/Brute_force_search "Brute force search").[\[3\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-3) Backtracking is a *[depth-first search](https://en.wikipedia.org/wiki/Depth-first_search "Depth-first search")* (in contrast to a *[breadth-first search](https://en.wikipedia.org/wiki/Breadth-first_search "Breadth-first search")*), because it will completely explore one branch to a possible solution before moving to another branch. Although it has been established that approximately 5.96 x 1026 final grids exist, a brute force algorithm can be a practical method to solve Sudoku puzzles. A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid.[\[4\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-4)[\[5\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-norvig2016-5)[\[6\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-6)[\[7\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Zelenski-7) Briefly, a program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell and places a "1" in that cell. When checking for violations, if it is discovered that the "1" is not allowed, the value is advanced to "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. This is repeated until the allowed value in the last (81st) cell is discovered. The animation shows how a Sudoku is solved with this method. The puzzle's clues (red numbers) remain fixed while the algorithm tests each unsolved cell with a possible solution. Notice that the algorithm may discard all the previously tested values if it finds the existing set does not fulfill the constraints of the Sudoku. Advantages of this method are: - A solution is guaranteed (as long as the puzzle is valid). - Solving time is mostly unrelated to [degree of difficulty](https://en.wikipedia.org/wiki/Degree_of_difficulty "Degree of difficulty").\[*[dubious](https://en.wikipedia.org/wiki/Wikipedia:Accuracy_dispute#Disputed_statement "Wikipedia:Accuracy dispute") – [discuss](https://en.wikipedia.org/wiki/Talk:Sudoku_solving_algorithms#Dubious "Talk:Sudoku solving algorithms")*\] - The algorithm (and therefore the program code) is simpler than other algorithms, especially compared to strong algorithms that ensure a solution to the most difficult puzzles. The disadvantage of this method is that the solving time may be slow compared to algorithms modeled after deductive methods. One programmer reported that such an algorithm may typically require as few as 15,000 cycles, or as many as 900,000 cycles to solve a Sudoku, each cycle being the change in position of a "pointer" as it moves through the cells of a Sudoku.[\[8\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-8)[\[9\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-9) A different approach which also uses backtracking, draws from the fact that in the solution to a standard sudoku the distribution for every individual symbol (value) must be one of only 46656 patterns. In manual sudoku solving this technique is referred to as pattern overlay or using templates and is confined to filling in the last values only. A library with all the possible patterns may get loaded or created at program start. Then every given symbol gets assigned a filtered set with those patterns, which are in accordance with the given clues. In the last step, the actual backtracking part, patterns from these sets are tried to be combined or overlaid in a non-conflicting way until the one permissible combination is hit upon. The Implementation is exceptionally easy when using bit vectors, because for all the tests only bit-wise logical operations are needed, instead of any nested iterations across rows and columns. Significant optimization can be achieved by reducing the sets of patterns even further during filtering. By testing every questionable pattern against all the reduced sets that were already accepted for the other symbols the total number of patterns left for backtracking is greatly diminished. And as with all sudoku brute-force techniques, run time can be vastly reduced by first applying some of the most simple solving practices which may fill in some 'easy' values. A Sudoku can be constructed to work against backtracking. Assuming the solver works from top to bottom (as in the animation), a puzzle with few clues (17), no clues in the top row, and has a solution "987654321" for the first row, would work in opposition to the algorithm. Thus the program would spend significant time "counting" upward before it arrives at the grid which satisfies the puzzle. In one case, a programmer found a brute force program required six hours to arrive at the solution for such a Sudoku (albeit using a 2008-era computer). Such a Sudoku can be solved nowadays in less than 1 second using an exhaustive search routine and faster processors.[\[10\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-10)p:25 ### Stochastic search / optimization methods \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=3 "Edit section: Stochastic search / optimization methods")\] Sudoku can be solved using stochastic (random-based) algorithms.[\[11\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Lewis,_R_\(2007\)_pp_387-401-11)[\[12\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Perez,_Meir_and_Marwala,_Tshilidzi_\(2008\)-12) An example of this method is to: 1. Randomly assign numbers to the blank cells in the grid. 2. Calculate the number of errors. 3. "Shuffle" the inserted numbers until the number of mistakes is reduced to zero. A solution to the puzzle is then found. Approaches for shuffling the numbers include [simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing "Simulated annealing"), [genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm "Genetic algorithm") and [tabu search](https://en.wikipedia.org/wiki/Tabu_search "Tabu search"). Stochastic-based algorithms are known to be fast, though perhaps not as fast as deductive techniques. Unlike the latter however, optimisation algorithms do not necessarily require problems to be logic-solvable, giving them the potential to solve a wider range of problems. Algorithms designed for graph colouring are also known to perform well with Sudokus.[\[13\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Lewis2015-13) It is also possible to express a Sudoku as an [integer linear programming](https://en.wikipedia.org/wiki/Integer_linear_programming "Integer linear programming") problem. Such approaches get close to a solution quickly, and can then use branching towards the end. The [simplex algorithm](https://en.wikipedia.org/wiki/Simplex_algorithm "Simplex algorithm") is able to solve proper Sudokus, indicating if the Sudoku is not valid (no solution). If there is more than one solution (non-proper Sudokus) the simplex algorithm will generally yield a solution with fractional amounts of more than one digit in some squares. However, for proper Sudokus, linear programming presolve techniques alone will deduce the solution without any need for simplex iterations. The logical rules used by presolve techniques for the reduction of LP problems include the set of logical rules used by humans to solve Sudokus. ### Constraint programming \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=4 "Edit section: Constraint programming")\] A Sudoku may also be modelled as a [constraint satisfaction problem](https://en.wikipedia.org/wiki/Constraint_satisfaction_problem "Constraint satisfaction problem"). In his paper *Sudoku as a Constraint Problem*,[\[14\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-14) Helmut Simonis describes many *reasoning algorithms* based on constraints which can be applied to model and solve problems. Some constraint solvers include a method to model and solve Sudokus, and a program may require fewer than 100 lines of code to solve a simple Sudoku.[\[15\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-15)[\[16\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-16) If the code employs a strong reasoning algorithm, incorporating backtracking is only needed for the most difficult Sudokus. An algorithm combining a constraint-model-based algorithm with backtracking would have the advantage of fast solving time – of the order of a few milliseconds[\[17\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-17) – and the ability to solve all sudokus.[\[5\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-norvig2016-5) ### Exact cover \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=5 "Edit section: Exact cover")\] Main article: [Exact cover § Sudoku](https://en.wikipedia.org/wiki/Exact_cover#Sudoku "Exact cover") Sudoku puzzles may be described as an [exact cover](https://en.wikipedia.org/wiki/Exact_cover "Exact cover") problem, or more precisely, an exact [hitting set](https://en.wikipedia.org/wiki/Hitting_set "Hitting set") problem. This allows for an elegant description of the problem and an efficient solution. Modelling Sudoku as an exact cover problem and using an algorithm such as [Knuth's Algorithm X](https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X "Knuth's Algorithm X") and his [Dancing Links](https://en.wikipedia.org/wiki/Dancing_Links "Dancing Links") technique "is the method of choice for rapid finding \[measured in microseconds\] of all possible solutions to Sudoku puzzles."[\[18\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-18) An alternative approach is the use of Gauss elimination in combination with column and row striking. ### Relations and residuals \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=6 "Edit section: Relations and residuals")\] Let *Q* be the 9x9 Sudoku matrix, *N* = {1, 2, 3, 4, 5, 6, 7, 8, 9}, and *X* represent a generic row, column, or block. *N* supplies symbols for filling *Q* as well as the [index set](https://en.wikipedia.org/wiki/Index_set "Index set") for the 9 elements of any *X*. The given elements *q* in *Q* represent a [univalent relation](https://en.wikipedia.org/wiki/Univalent_relation "Univalent relation") from *Q* to *N*. The solution *R* is a *total relation* and hence a [function](https://en.wikipedia.org/wiki/Function_\(mathematics\) "Function (mathematics)"). Sudoku rules require that the [restriction](https://en.wikipedia.org/wiki/Restriction_\(mathematics\) "Restriction (mathematics)") of *R* to *X* is a [bijection](https://en.wikipedia.org/wiki/Bijection "Bijection"), so any partial solution *C*, restricted to an *X*, is a [partial permutation](https://en.wikipedia.org/wiki/Partial_permutation "Partial permutation") of *N*. Let *T* = { *X* : *X* is a row, column, or block of *Q* }, so *T* has 27 elements. An *arrangement* is either a partial permutation or a [permutation](https://en.wikipedia.org/wiki/Permutation "Permutation") on *N*. Let *Z* be the set of all arrangements on *N*. A partial solution *C* can be reformulated to include the rules as a [composition of relations](https://en.wikipedia.org/wiki/Composition_of_relations "Composition of relations") *A* (one-to-three) and *B* requiring compatible arrangements: Q → A T → B Z with A ; B ⊆ C . {\\displaystyle Q\\xrightarrow {A} T\\xrightarrow {B} Z\\quad {\\text{with}}\\quad A;B\\subseteq C.} ![{\\displaystyle Q\\xrightarrow {A} T\\xrightarrow {B} Z\\quad {\\text{with}}\\quad A;B\\subseteq C.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/6db2fdfae459f757b00c8067f13a2fd044ab6313) Solution of the puzzle, suggestions for new *q* to enter *Q*, come from prohibited arrangements C ¯ , {\\displaystyle {\\bar {C}},} ![{\\displaystyle {\\bar {C}},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/ed67eef04684aeb46cd59c10328a9a3f25ffa81c), the [complement](https://en.wikipedia.org/wiki/Set_complement "Set complement") of *C* in *Q*x*Z*: useful tools in the calculus of relations are [residuals](https://en.wikipedia.org/wiki/Composition_of_relations#Quotients "Composition of relations"): A ∖ C \= A T ; C ¯ ¯ {\\displaystyle A\\backslash C={\\overline {A^{T};{\\bar {C}}}}} ![{\\displaystyle A\\backslash C={\\overline {A^{T};{\\bar {C}}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/8a7d0045615e1dbfb9c9526efd0820d81c5704e2) maps *T* to *Z*, and C / B \= C ¯ ; B T ¯ {\\displaystyle C/B={\\overline {{\\bar {C}};B^{T}}}} ![{\\displaystyle C/B={\\overline {{\\bar {C}};B^{T}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/af1fa9b7f09ed6f4cb2986b93dbfa6b50c9b82e6) maps *Q* to *T*. ## See also \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=7 "Edit section: See also")\] - [Sudoku](https://en.wikipedia.org/wiki/Sudoku "Sudoku") - [Mathematics of Sudoku](https://en.wikipedia.org/wiki/Mathematics_of_Sudoku "Mathematics of Sudoku") - [Combinatorial explosion](https://en.wikipedia.org/wiki/Combinatorial_explosion "Combinatorial explosion") (with summary of grid count of Sudoku compared to Latin squares) - [Glossary of Sudoku](https://en.wikipedia.org/wiki/Glossary_of_Sudoku "Glossary of Sudoku") ## References \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=8 "Edit section: References")\] 1. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-1)** Mahmood, Yasser (2009). ["More about Sudoku"](https://pi.math.cornell.edu/~mec/Summer2009/Mahmood/More.html#:~:text=A%20well-formed%20Sudoku%20puzzle,that%20has%20a%20unique%20solution.). *Cornell University*. Retrieved 2024-11-26. 2. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-difficult_17_clue_2-0)** ["Star Burst - Polar Graph"](https://www.flickr.com/photos/npcomplete/2361922699) A polar chart showing a solution path for a Sudoku (Star Burst) using an exhaustive search routine and comment about 17-clue Sudoku. 3. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-3)** [http://intelligence.worldofcomputing/brute-force-search](http://intelligence.worldofcomputing.net/ai-search/brute-force-search.html#.WPWK6oWcEiQ) Brute Force Search, December 14th, 2009. 4. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-4)** ["Backtracking - Set 7 (Sudoku)"](https://web.archive.org/web/20160828164622/http://www.geeksforgeeks.org/backtracking-set-7-suduku/). *GeeksforGeeks*. Archived from [the original](http://www.geeksforgeeks.org/backtracking-set-7-suduku/) on 2016-08-28. Retrieved 24 December 2016. 5. ^ [***a***](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-norvig2016_5-0) [***b***](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-norvig2016_5-1) Norvig, Peter. ["Solving Every Sudoku Puzzle"](http://www.norvig.com/sudoku.html). *Peter Norvig (personal website)*. Retrieved 24 December 2016. 6. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-6)** ["Chart of Cells Visited for Solution"](https://www.flickr.com/photos/npcomplete/2341937186) A chart showing a solution path to a difficult Sudoku. 7. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Zelenski_7-0)** Zelenski, Julie (July 16, 2008). [*Lecture 11 \| Programming Abstractions (Stanford)*](https://www.youtube.com/watch?v=p-gpaIGRCQI). Stanford Computer Science Department. 8. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-8)** ["Star Burst Leo - Polar Graph"](https://www.flickr.com/photos/npcomplete/2384354604) A polar chart showing a solution path for a Sudoku (Star Burst Leo) using an exhaustive search routine. 9. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-9)** ["Chart of Cells Visited for Solution"](https://www.flickr.com/photos/npcomplete/2341937186) A chart showing a solution path for a difficult Sudoku using an exhaustive search routine. 10. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-10)** McGuire, Gary; Tugemann, Bastian; Civario, Gilles (2012). ["A Game of Sudoku"](https://www.researchgate.net/publication/51978217_There_Is_No_16-Clue_Sudoku_Solving_the_Sudoku_Minimum_Number_of_Clues_Problem_via_Hitting_Set_Enumeration/link/64e68f7b0453074fbda95dbe/download?_tp=eyJjb250ZXh0Ijp7ImZpcnN0UGFnZSI6InB1YmxpY2F0aW9uIiwicGFnZSI6InB1YmxpY2F0aW9uIn19) (PDF). *ResearchGate*: 25. Retrieved 2024-11-27. 11. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Lewis,_R_\(2007\)_pp_387-401_11-0)** Lewis, R (2007) *Metaheuristics Can Solve Sudoku Puzzles* Journal of Heuristics, vol. 13 (4), pp 387-401. 12. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Perez,_Meir_and_Marwala,_Tshilidzi_\(2008\)_12-0)** Perez, Meir and Marwala, Tshilidzi (2008) *Stochastic Optimization Approaches for Solving Sudoku* arXiv:0805.0697. 13. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Lewis2015_13-0)** Lewis, R. *A Guide to Graph Colouring: Algorithms and Applications*. Springer International Publishers, 2015. 14. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-14)** Simonis, Helmut (2005). "Sudoku as a Constraint Problem". [CiteSeerX](https://en.wikipedia.org/wiki/CiteSeerX_\(identifier\) "CiteSeerX (identifier)") [10\.1.1.88.2964](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.88.2964). "paper presented at the Eleventh International Conference on Principles and Practice of Constraint Programming" 15. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-15)** Multiple Authors. ["Java Constraint Programming solver"](http://jacop.osolpro.com/) (Java). *JaCoP*. Krzysztof Kuchcinski & Radoslaw Szymanek. Retrieved 8 December 2016. 16. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-16)** Rhollor. ["Sudokusolver"](https://github.com/Rhollor/SudoKuSolver) (C++). *GitHub*. Rhollor. Retrieved 8 December 2016. 17. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-17)** ["Sudoku - Rosetta Code"](https://rosettacode.org/wiki/Sudoku#Constraint_Satisfaction_.28Norvig.29). *rosettacode.org*. Retrieved 2021-11-30. 18. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-18)** Hanson, Robert M. (16 August 2022). ["Exact Cover Matrix"](https://www.stolaf.edu/people/hansonr/sudoku/exactcovermatrix.htm). ## External links \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=9 "Edit section: External links")\] - <http://diuf.unifr.ch/pai/people/juillera/Sudoku/Sudoku.html> *Sudoku Explainer by Nicolas Juillerat* (Popular for rating Sudokus in general) [Archived](https://web.archive.org/web/20131112230157/http://diuf.unifr.ch/pai/people/juillera/Sudoku/Sudoku.html) 2013-11-12 at the [Wayback Machine](https://en.wikipedia.org/wiki/Wayback_Machine "Wayback Machine") - [A Pencil-and-Paper Algorithm for Solving Sudoku Puzzles](http://www.ams.org/notices/200904/rtx090400460p.pdf) ![](https://en.wikipedia.org/wiki/Special:CentralAutoLogin/start?useformat=desktop&type=1x1&usesul3=1) Retrieved from "<https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&oldid=1316656345>" [Categories](https://en.wikipedia.org/wiki/Help:Category "Help:Category"): - [Sudoku](https://en.wikipedia.org/wiki/Category:Sudoku "Category:Sudoku") - [Abstract strategy games](https://en.wikipedia.org/wiki/Category:Abstract_strategy_games "Category:Abstract strategy games") - [Search algorithms](https://en.wikipedia.org/wiki/Category:Search_algorithms "Category:Search algorithms") Hidden categories: - [Articles with short description](https://en.wikipedia.org/wiki/Category:Articles_with_short_description "Category:Articles with short description") - [Short description is different from Wikidata](https://en.wikipedia.org/wiki/Category:Short_description_is_different_from_Wikidata "Category:Short description is different from Wikidata") - [All accuracy disputes](https://en.wikipedia.org/wiki/Category:All_accuracy_disputes "Category:All accuracy disputes") - [Articles with disputed statements from June 2023](https://en.wikipedia.org/wiki/Category:Articles_with_disputed_statements_from_June_2023 "Category:Articles with disputed statements from June 2023") - [Webarchive template wayback links](https://en.wikipedia.org/wiki/Category:Webarchive_template_wayback_links "Category:Webarchive template wayback links") - This page was last edited on 13 October 2025, at 19:37 (UTC). - Text is available under the [Creative Commons Attribution-ShareAlike 4.0 License](https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License "Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License"); additional terms may apply. By using this site, you agree to the [Terms of Use](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use "foundation:Special:MyLanguage/Policy:Terms of Use") and [Privacy Policy](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy "foundation:Special:MyLanguage/Policy:Privacy policy"). Wikipedia® is a registered trademark of the [Wikimedia Foundation, Inc.](https://wikimediafoundation.org/), a non-profit organization. - [Privacy policy](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy) - [About Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:About) - [Disclaimers](https://en.wikipedia.org/wiki/Wikipedia:General_disclaimer) - [Contact Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:Contact_us) - [Legal & safety contacts](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Legal:Wikimedia_Foundation_Legal_and_Safety_Contact_Information) - [Code of Conduct](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct) - [Developers](https://developer.wikimedia.org/) - [Statistics](https://stats.wikimedia.org/#/en.wikipedia.org) - [Cookie statement](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement) - [Mobile view](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&mobileaction=toggle_view_mobile) - [![Wikimedia Foundation](https://en.wikipedia.org/static/images/footer/wikimedia.svg)](https://www.wikimedia.org/) - [![Powered by MediaWiki](https://en.wikipedia.org/w/resources/assets/mediawiki_compact.svg)](https://www.mediawiki.org/) Search Toggle the table of contents Sudoku solving algorithms 5 languages [Add topic](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms)
Readable Markdown
From Wikipedia, the free encyclopedia [![A typical Sudoku puzzle, a 9x9 grid with several numbers missing](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg/330px-Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg.png)](https://en.wikipedia.org/wiki/File:Sudoku_Puzzle_by_L2G-20050714_standardized_layout.svg) A typical Sudoku puzzle A standard [Sudoku](https://en.wikipedia.org/wiki/Sudoku "Sudoku") contains 81 cells, in a 9×9 grid, and has 9 boxes, each box being the intersection of the first, middle, or last 3 rows, and the first, middle, or last 3 columns. Each cell may contain a number from one to nine, and each number can only occur once in each row, column, and box. A Sudoku starts with some cells containing numbers (*clues*), and the goal is to solve the remaining cells. Proper Sudokus have one solution.[\[1\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-1) Players and investigators use a wide range of computer algorithms to solve Sudokus, study their properties, and make new puzzles, including Sudokus with interesting symmetries and other properties. There are several computer algorithms that will solve 9×9 puzzles (n = 9) in fractions of a second, but [combinatorial explosion](https://en.wikipedia.org/wiki/Combinatorial_explosion "Combinatorial explosion") occurs as n increases, creating limits to the properties of Sudokus that can be constructed, analyzed, and solved as n increases. [![](https://upload.wikimedia.org/wikipedia/commons/8/8c/Sudoku_solved_by_bactracking.gif)](https://en.wikipedia.org/wiki/File:Sudoku_solved_by_bactracking.gif) A Sudoku (top) being solved by **backtracking**. Each cell is tested for a valid number, moving "back" when there is a violation, and moving forward again until the puzzle is solved. [![](https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Sudoku_puzzle_hard_for_brute_force.svg/330px-Sudoku_puzzle_hard_for_brute_force.svg.png)](https://en.wikipedia.org/wiki/File:Sudoku_puzzle_hard_for_brute_force.svg) A Sudoku designed to work against the brute force algorithm[\[2\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-difficult_17_clue-2) Some hobbyists have developed computer programs that will solve Sudoku puzzles using a [backtracking](https://en.wikipedia.org/wiki/Backtracking "Backtracking") algorithm, which is a type of [brute force search](https://en.wikipedia.org/wiki/Brute_force_search "Brute force search").[\[3\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-3) Backtracking is a *[depth-first search](https://en.wikipedia.org/wiki/Depth-first_search "Depth-first search")* (in contrast to a *[breadth-first search](https://en.wikipedia.org/wiki/Breadth-first_search "Breadth-first search")*), because it will completely explore one branch to a possible solution before moving to another branch. Although it has been established that approximately 5.96 x 1026 final grids exist, a brute force algorithm can be a practical method to solve Sudoku puzzles. A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid.[\[4\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-4)[\[5\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-norvig2016-5)[\[6\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-6)[\[7\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Zelenski-7) Briefly, a program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell and places a "1" in that cell. When checking for violations, if it is discovered that the "1" is not allowed, the value is advanced to "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. This is repeated until the allowed value in the last (81st) cell is discovered. The animation shows how a Sudoku is solved with this method. The puzzle's clues (red numbers) remain fixed while the algorithm tests each unsolved cell with a possible solution. Notice that the algorithm may discard all the previously tested values if it finds the existing set does not fulfill the constraints of the Sudoku. Advantages of this method are: - A solution is guaranteed (as long as the puzzle is valid). - Solving time is mostly unrelated to [degree of difficulty](https://en.wikipedia.org/wiki/Degree_of_difficulty "Degree of difficulty").\[*[dubious](https://en.wikipedia.org/wiki/Wikipedia:Accuracy_dispute#Disputed_statement "Wikipedia:Accuracy dispute") – [discuss](https://en.wikipedia.org/wiki/Talk:Sudoku_solving_algorithms#Dubious "Talk:Sudoku solving algorithms")*\] - The algorithm (and therefore the program code) is simpler than other algorithms, especially compared to strong algorithms that ensure a solution to the most difficult puzzles. The disadvantage of this method is that the solving time may be slow compared to algorithms modeled after deductive methods. One programmer reported that such an algorithm may typically require as few as 15,000 cycles, or as many as 900,000 cycles to solve a Sudoku, each cycle being the change in position of a "pointer" as it moves through the cells of a Sudoku.[\[8\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-8)[\[9\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-9) A different approach which also uses backtracking, draws from the fact that in the solution to a standard sudoku the distribution for every individual symbol (value) must be one of only 46656 patterns. In manual sudoku solving this technique is referred to as pattern overlay or using templates and is confined to filling in the last values only. A library with all the possible patterns may get loaded or created at program start. Then every given symbol gets assigned a filtered set with those patterns, which are in accordance with the given clues. In the last step, the actual backtracking part, patterns from these sets are tried to be combined or overlaid in a non-conflicting way until the one permissible combination is hit upon. The Implementation is exceptionally easy when using bit vectors, because for all the tests only bit-wise logical operations are needed, instead of any nested iterations across rows and columns. Significant optimization can be achieved by reducing the sets of patterns even further during filtering. By testing every questionable pattern against all the reduced sets that were already accepted for the other symbols the total number of patterns left for backtracking is greatly diminished. And as with all sudoku brute-force techniques, run time can be vastly reduced by first applying some of the most simple solving practices which may fill in some 'easy' values. A Sudoku can be constructed to work against backtracking. Assuming the solver works from top to bottom (as in the animation), a puzzle with few clues (17), no clues in the top row, and has a solution "987654321" for the first row, would work in opposition to the algorithm. Thus the program would spend significant time "counting" upward before it arrives at the grid which satisfies the puzzle. In one case, a programmer found a brute force program required six hours to arrive at the solution for such a Sudoku (albeit using a 2008-era computer). Such a Sudoku can be solved nowadays in less than 1 second using an exhaustive search routine and faster processors.[\[10\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-10)p:25 ### Stochastic search / optimization methods \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=3 "Edit section: Stochastic search / optimization methods")\] Sudoku can be solved using stochastic (random-based) algorithms.[\[11\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Lewis,_R_\(2007\)_pp_387-401-11)[\[12\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Perez,_Meir_and_Marwala,_Tshilidzi_\(2008\)-12) An example of this method is to: 1. Randomly assign numbers to the blank cells in the grid. 2. Calculate the number of errors. 3. "Shuffle" the inserted numbers until the number of mistakes is reduced to zero. A solution to the puzzle is then found. Approaches for shuffling the numbers include [simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing "Simulated annealing"), [genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm "Genetic algorithm") and [tabu search](https://en.wikipedia.org/wiki/Tabu_search "Tabu search"). Stochastic-based algorithms are known to be fast, though perhaps not as fast as deductive techniques. Unlike the latter however, optimisation algorithms do not necessarily require problems to be logic-solvable, giving them the potential to solve a wider range of problems. Algorithms designed for graph colouring are also known to perform well with Sudokus.[\[13\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-Lewis2015-13) It is also possible to express a Sudoku as an [integer linear programming](https://en.wikipedia.org/wiki/Integer_linear_programming "Integer linear programming") problem. Such approaches get close to a solution quickly, and can then use branching towards the end. The [simplex algorithm](https://en.wikipedia.org/wiki/Simplex_algorithm "Simplex algorithm") is able to solve proper Sudokus, indicating if the Sudoku is not valid (no solution). If there is more than one solution (non-proper Sudokus) the simplex algorithm will generally yield a solution with fractional amounts of more than one digit in some squares. However, for proper Sudokus, linear programming presolve techniques alone will deduce the solution without any need for simplex iterations. The logical rules used by presolve techniques for the reduction of LP problems include the set of logical rules used by humans to solve Sudokus. ### Constraint programming \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=4 "Edit section: Constraint programming")\] A Sudoku may also be modelled as a [constraint satisfaction problem](https://en.wikipedia.org/wiki/Constraint_satisfaction_problem "Constraint satisfaction problem"). In his paper *Sudoku as a Constraint Problem*,[\[14\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-14) Helmut Simonis describes many *reasoning algorithms* based on constraints which can be applied to model and solve problems. Some constraint solvers include a method to model and solve Sudokus, and a program may require fewer than 100 lines of code to solve a simple Sudoku.[\[15\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-15)[\[16\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-16) If the code employs a strong reasoning algorithm, incorporating backtracking is only needed for the most difficult Sudokus. An algorithm combining a constraint-model-based algorithm with backtracking would have the advantage of fast solving time – of the order of a few milliseconds[\[17\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-17) – and the ability to solve all sudokus.[\[5\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-norvig2016-5) Sudoku puzzles may be described as an [exact cover](https://en.wikipedia.org/wiki/Exact_cover "Exact cover") problem, or more precisely, an exact [hitting set](https://en.wikipedia.org/wiki/Hitting_set "Hitting set") problem. This allows for an elegant description of the problem and an efficient solution. Modelling Sudoku as an exact cover problem and using an algorithm such as [Knuth's Algorithm X](https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X "Knuth's Algorithm X") and his [Dancing Links](https://en.wikipedia.org/wiki/Dancing_Links "Dancing Links") technique "is the method of choice for rapid finding \[measured in microseconds\] of all possible solutions to Sudoku puzzles."[\[18\]](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_note-18) An alternative approach is the use of Gauss elimination in combination with column and row striking. ### Relations and residuals \[[edit](https://en.wikipedia.org/w/index.php?title=Sudoku_solving_algorithms&action=edit&section=6 "Edit section: Relations and residuals")\] Let *Q* be the 9x9 Sudoku matrix, *N* = {1, 2, 3, 4, 5, 6, 7, 8, 9}, and *X* represent a generic row, column, or block. *N* supplies symbols for filling *Q* as well as the [index set](https://en.wikipedia.org/wiki/Index_set "Index set") for the 9 elements of any *X*. The given elements *q* in *Q* represent a [univalent relation](https://en.wikipedia.org/wiki/Univalent_relation "Univalent relation") from *Q* to *N*. The solution *R* is a *total relation* and hence a [function](https://en.wikipedia.org/wiki/Function_\(mathematics\) "Function (mathematics)"). Sudoku rules require that the [restriction](https://en.wikipedia.org/wiki/Restriction_\(mathematics\) "Restriction (mathematics)") of *R* to *X* is a [bijection](https://en.wikipedia.org/wiki/Bijection "Bijection"), so any partial solution *C*, restricted to an *X*, is a [partial permutation](https://en.wikipedia.org/wiki/Partial_permutation "Partial permutation") of *N*. Let *T* = { *X* : *X* is a row, column, or block of *Q* }, so *T* has 27 elements. An *arrangement* is either a partial permutation or a [permutation](https://en.wikipedia.org/wiki/Permutation "Permutation") on *N*. Let *Z* be the set of all arrangements on *N*. A partial solution *C* can be reformulated to include the rules as a [composition of relations](https://en.wikipedia.org/wiki/Composition_of_relations "Composition of relations") *A* (one-to-three) and *B* requiring compatible arrangements: ![{\\displaystyle Q\\xrightarrow {A} T\\xrightarrow {B} Z\\quad {\\text{with}}\\quad A;B\\subseteq C.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/6db2fdfae459f757b00c8067f13a2fd044ab6313) Solution of the puzzle, suggestions for new *q* to enter *Q*, come from prohibited arrangements ![{\\displaystyle {\\bar {C}},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/ed67eef04684aeb46cd59c10328a9a3f25ffa81c), the [complement](https://en.wikipedia.org/wiki/Set_complement "Set complement") of *C* in *Q*x*Z*: useful tools in the calculus of relations are [residuals](https://en.wikipedia.org/wiki/Composition_of_relations#Quotients "Composition of relations"): ![{\\displaystyle A\\backslash C={\\overline {A^{T};{\\bar {C}}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/8a7d0045615e1dbfb9c9526efd0820d81c5704e2) maps *T* to *Z*, and ![{\\displaystyle C/B={\\overline {{\\bar {C}};B^{T}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/af1fa9b7f09ed6f4cb2986b93dbfa6b50c9b82e6) maps *Q* to *T*. - [Sudoku](https://en.wikipedia.org/wiki/Sudoku "Sudoku") - [Mathematics of Sudoku](https://en.wikipedia.org/wiki/Mathematics_of_Sudoku "Mathematics of Sudoku") - [Combinatorial explosion](https://en.wikipedia.org/wiki/Combinatorial_explosion "Combinatorial explosion") (with summary of grid count of Sudoku compared to Latin squares) - [Glossary of Sudoku](https://en.wikipedia.org/wiki/Glossary_of_Sudoku "Glossary of Sudoku") 1. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-1)** Mahmood, Yasser (2009). ["More about Sudoku"](https://pi.math.cornell.edu/~mec/Summer2009/Mahmood/More.html#:~:text=A%20well-formed%20Sudoku%20puzzle,that%20has%20a%20unique%20solution.). *Cornell University*. Retrieved 2024-11-26. 2. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-difficult_17_clue_2-0)** ["Star Burst - Polar Graph"](https://www.flickr.com/photos/npcomplete/2361922699) A polar chart showing a solution path for a Sudoku (Star Burst) using an exhaustive search routine and comment about 17-clue Sudoku. 3. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-3)** [http://intelligence.worldofcomputing/brute-force-search](http://intelligence.worldofcomputing.net/ai-search/brute-force-search.html#.WPWK6oWcEiQ) Brute Force Search, December 14th, 2009. 4. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-4)** ["Backtracking - Set 7 (Sudoku)"](https://web.archive.org/web/20160828164622/http://www.geeksforgeeks.org/backtracking-set-7-suduku/). *GeeksforGeeks*. Archived from [the original](http://www.geeksforgeeks.org/backtracking-set-7-suduku/) on 2016-08-28. Retrieved 24 December 2016. 5. ^ [***a***](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-norvig2016_5-0) [***b***](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-norvig2016_5-1) Norvig, Peter. ["Solving Every Sudoku Puzzle"](http://www.norvig.com/sudoku.html). *Peter Norvig (personal website)*. Retrieved 24 December 2016. 6. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-6)** ["Chart of Cells Visited for Solution"](https://www.flickr.com/photos/npcomplete/2341937186) A chart showing a solution path to a difficult Sudoku. 7. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Zelenski_7-0)** Zelenski, Julie (July 16, 2008). [*Lecture 11 \| Programming Abstractions (Stanford)*](https://www.youtube.com/watch?v=p-gpaIGRCQI). Stanford Computer Science Department. 8. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-8)** ["Star Burst Leo - Polar Graph"](https://www.flickr.com/photos/npcomplete/2384354604) A polar chart showing a solution path for a Sudoku (Star Burst Leo) using an exhaustive search routine. 9. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-9)** ["Chart of Cells Visited for Solution"](https://www.flickr.com/photos/npcomplete/2341937186) A chart showing a solution path for a difficult Sudoku using an exhaustive search routine. 10. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-10)** McGuire, Gary; Tugemann, Bastian; Civario, Gilles (2012). ["A Game of Sudoku"](https://www.researchgate.net/publication/51978217_There_Is_No_16-Clue_Sudoku_Solving_the_Sudoku_Minimum_Number_of_Clues_Problem_via_Hitting_Set_Enumeration/link/64e68f7b0453074fbda95dbe/download?_tp=eyJjb250ZXh0Ijp7ImZpcnN0UGFnZSI6InB1YmxpY2F0aW9uIiwicGFnZSI6InB1YmxpY2F0aW9uIn19) (PDF). *ResearchGate*: 25. Retrieved 2024-11-27. 11. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Lewis,_R_\(2007\)_pp_387-401_11-0)** Lewis, R (2007) *Metaheuristics Can Solve Sudoku Puzzles* Journal of Heuristics, vol. 13 (4), pp 387-401. 12. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Perez,_Meir_and_Marwala,_Tshilidzi_\(2008\)_12-0)** Perez, Meir and Marwala, Tshilidzi (2008) *Stochastic Optimization Approaches for Solving Sudoku* arXiv:0805.0697. 13. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-Lewis2015_13-0)** Lewis, R. *A Guide to Graph Colouring: Algorithms and Applications*. Springer International Publishers, 2015. 14. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-14)** Simonis, Helmut (2005). "Sudoku as a Constraint Problem". [CiteSeerX](https://en.wikipedia.org/wiki/CiteSeerX_\(identifier\) "CiteSeerX (identifier)") [10\.1.1.88.2964](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.88.2964). "paper presented at the Eleventh International Conference on Principles and Practice of Constraint Programming" 15. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-15)** Multiple Authors. ["Java Constraint Programming solver"](http://jacop.osolpro.com/) (Java). *JaCoP*. Krzysztof Kuchcinski & Radoslaw Szymanek. Retrieved 8 December 2016. 16. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-16)** Rhollor. ["Sudokusolver"](https://github.com/Rhollor/SudoKuSolver) (C++). *GitHub*. Rhollor. Retrieved 8 December 2016. 17. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-17)** ["Sudoku - Rosetta Code"](https://rosettacode.org/wiki/Sudoku#Constraint_Satisfaction_.28Norvig.29). *rosettacode.org*. Retrieved 2021-11-30. 18. **[^](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#cite_ref-18)** Hanson, Robert M. (16 August 2022). ["Exact Cover Matrix"](https://www.stolaf.edu/people/hansonr/sudoku/exactcovermatrix.htm). - <http://diuf.unifr.ch/pai/people/juillera/Sudoku/Sudoku.html> *Sudoku Explainer by Nicolas Juillerat* (Popular for rating Sudokus in general) [Archived](https://web.archive.org/web/20131112230157/http://diuf.unifr.ch/pai/people/juillera/Sudoku/Sudoku.html) 2013-11-12 at the [Wayback Machine](https://en.wikipedia.org/wiki/Wayback_Machine "Wayback Machine") - [A Pencil-and-Paper Algorithm for Solving Sudoku Puzzles](http://www.ams.org/notices/200904/rtx090400460p.pdf)
Shard152 (laksa)
Root Hash17790707453426894952
Unparsed URLorg,wikipedia!en,/wiki/Sudoku_solving_algorithms s443