![]() ![]() ![]() It then traverses over the sorted cells, setting trying to set the cell’s candidates. If not, it collects all non assigned cells and sort them based on their cardinality (preferring cells with fewer candidates). It first examines if the puzzle already been solved. Our first trial for solving the puzzle is by a naive backtracking algorithm. Backtracking is a classical depth-first search. Data structure and some important methods of the Sudoku class The following Java code includes some important methods of the Sudoku class. The full Java code of the SudokuSolver is publicly available on. finally, we also holds a list of non-assigned cells in the puzzle. In addition we keep for each row/column/block (a unit for short) a BitSet that maintains all values that have already been set in this unit. Any constraint entry (i,j) represents all candidates that can be legally assigned to cell (i,j). BitSet is a Java class that can be used to efficiently maintain a set of values, including adding, removing, and querying the containment of a specific value. In addition, we manage an auxiliary NxN matrix of BitSet objects. At the beginning, only clue cells are set with their values, while all other cells are set to zero. We represent a Sudoku puzzle by an NxN matrix holding all values that have already been set on the grid. I’ll also report the results of some experiments I conducted on a popular benchmark of 95 9×9 puzzles which had already been used in Norvig study. ![]() I’ll begin with the search algorithm, and then describe the heuristics. In the following I will describe the HS-solver that is based on backtracking search, integrated with the human strategies. This is especially useful for (the few) tasks for which humans are still superior to machines. Realizing the difficulty in searching over huge spaces, it is inspired from the ways humans tend to solve the problem and whether human strategies can be applied to improve our solver performance. Heuristic search is one of my favorite AI techniques. In this study I follow Norvig by integrating common Sudoku strategies, popular among Sudoku fans, into the search process. Peter Norvig, the famous AI pioneer, provided a Python code for a Sudoku solver based on integrating CSP with search. Genetic algorithms, and modeling Sudoku as an exact cover problem while using the dancing links techniques. There are many approaches for solving Sudoku puzzles, including CSP-based solutions , Unfortunately, Sudoku is an NP-complete problem, when generalized to N × N grids, in the sense that all known solvable algorithms do so inefficiently in spite of the fact that if a candidate solution is given, it takes only polynomial time to check its correctness. Therefore, a naive search approach is unlikely to be efficient so we need some domain knowledge (called heuristics in AI terminology ) to direct our problem solver. Right: its solutionĪs a lazy scientist who hates hard work but also can’t stand unsolved puzzles, I decided to write a Sudoku solver program based on searching over all legal assignments for a given puzzle. This is an early 'ultimate puzzle' but this crown has been usurped by the puzzle created by Arto Inkala, which is also in the example list.Figure 1: Left: A Sudoku puzzle. With the community's help I hope to extend the documentation here.įor those people wondering why " Escargot" cannot be solved by the solver, there is an article on this special Sudoku here. If you are interested in the concepts behind creation and grading, there is a PDF document here called Sudoku Creation and Grading. Many strategies can be further extended and we do not have a complete theory of all Sudoku puzzles. This strategy list is by no means complete. These are now included for the first time on this site. There are naturally special strategies for Jigsaw and Killers because of their differences. They are definitely worth presenting as a demonstration of people's ingenuity but you will only need to have recourse to them on the extreme puzzles. Do read the introductory articles Introducing Chains and Links and Weak and Strong Links.Įxotic strategies do overlap with chaining ones, but they have a peculiar flavour of their own and some wonderful, if obscure, logic. Thus, for example, Remote Pairs are a subset of XY-Chains that is, XY-Chains is a more general approach of which Remote Pairs are a specific instance. You will find, if you read through this group, that earlier strategies become part of a more general theory as the theme develops. This theme is all about bi-value (only two candidates left in the same cell) and bi-location (only two occurrences of a particular candidate left in the same unit) pairs and the incredible number of deductions one can make from them. With chaining strategies, there is definitely a theme going through them. ![]()
0 Comments
Leave a Reply. |