Sudoku Solver

Simple Operations
Hole Operations
Phantom Operations
Crowding Operations
Waiting for JS load.

Instructions

Click on a square to select it, then type a number to put the number in the selected square. Once all of the numbers making up the initial state of the puzzle have been entered, click "Solve" to run the solver, and the solution will appear. If you entered something incorrectly by mistake, or want to try a different puzzle, click "Reset" to delete any numbers that aren't in bold, or "Clear" to clear the entire board.

About the Solver

This is my algorithmic Sudoku solver, originally made in Java (download the JAR or source code), and now ported to Javascript and updated. While solving a Sudoku puzzle with brute force is easy, brute force solutions often don't make sense in other real-world applications, and it is good practice to consider algorithmic solutions instead.

As such, I set out to create a fast algorithmic solver, based on my own experience playing Sudoku, and the tactics I ended up using. I found that these tactics could be broken into four basic categories: Simple, Hole, Phantom, and Crowding. Each of these uses the rules of Sudoku in different ways, trying to figure out where certain numbers are or are not allowed. You can enable or disable each of these rulesets to see whether a puzzle can be solved without them - the type of tactic needed to finish a solution is used to determine the difficulty.

Simple Operations - Easy: Simple Operations describe the basic rules of the game. Each column, row, and group must contain no more than a single instance of each number. For example, if there is a 5 in one space, another 5 cannot be placed in the same row, column, or group.

Hole Operations - Medium: Hole Operations are those that rely on there only being one place a number could go within a column, row, or group. For example, if a column has three remaining spaces for a 1, 4, and 7, but two of the spaces have a 4 in the same row, then the 4 must go in the third space.

Phantom Operations - Hard: Phantom Operations are a way of translating the constraints of a group into constraints on columns and rows. For example, if there are only two remaining spaces in a group for an 8, and they line up, then the rest of the column or row that they line up with cannot contain an 8.

Crowding Operations - Evil: Crowding Operations are an extension of Hole Operations into multiple spaces. While a hole can only describe a single value in a single space, Crowding Operations describe a set of n values that can fit into n spaces, which therefore prevents those values being used elsewhere in the row, column, or group. For example, if a group has four spaces for a 2, 6, 7, and 9, but two of those spaces only allow 2 and 6, then the other spaces can only allow 7 and 9.

Future Work

There are some puzzles that this solver cannot solve with its current ruleset, and obviously the next step would likely be addressing these, perhaps through the use of an Arc Consistency algorithm - or even using artificial intelligence, as detailed in a great presentation by Kudzo Ahegbebu with OpenAI.

Another step, to prove the utility of the algorithmic solver, would be to allow larger boards, such as a 16x16 or 25x25, though these would obviously be much more laborious ofr a human to input, so a puzzle generator would also probably be required.

Finally, perhaps the end goal would be to allow users to upload real-life pictures from their mobile devices, detect and load Sudoku puzzles in the image, and solve them, removing the need for the user to manually enter all of the numbers themselves.