# NNM Sudoku Magic

{{matrixForImport.length}}
{{matrixForExport}}
 {{stat.label}} {{stat.calcTotal()}} ({{stat.calcTotal()*100/stat.max | number:0}}%)

## Congratulations! You have solved the Sudoku puzzle!

 {{\$index+1}} 6 {{\$index+7}}

Here you can configure what should be shown on the Gameboard page.

Shows a textarea where you can import a Sudoku matrix into the Gameboard.
Shows a mini matrix that is a copy of the current Gameboard. This mini matrix can be copied and saved for later imports.
Shows information about how much of the puzzle that is solved and the state of the cells.
Will, for each cell in the matrix, indicate which of the values 1-9 that still are potential to use without breaking the rules of the game.
Will, for each cell in the matrix, indicate if there is only one potential value left to use.
Will, for each cell in the matrix, indicate if any of the cell's potential values is missing as a potential value for all other cells in the same row, column or 3-by-3 square.

A good starting point if you are new to Sudoku is to look at Wikipedia's Sudoku page. I will not go into details about the rules, history and mathematics in the documentation below, instead I will focus on the details for the NNM Sudoku Magic implementation.

## Gameboard

The Gameboard consists of 81 cells, layed out in a 9x9 matrix. There are nine rows, nine column and also nine 3-by-3 squares in the matrix.

### Cell

Each cell has:

• a current state
• a current value (may be undefined)
• a set of potential values (in the range 1-9)
• a unique potential value (may be undefined)
• three sets of neighbours, i.e. the eight cells that are in the same row, the same column or the same 3-by-3 square, which means that each cell has twenty neighbours (when duplicates are removed)

#### Neighbour cell

The cells in the same row, column or 3-by-3 square as a cell C are called C's neighbours. There are eight neigbours in the same row, eight neighbours in the same column and eight neighbours in the same 3-by-3 square, but four of these are duplicates, so each cell has a total of twenty unique neighbour cells.

#### Cell states

A cell is always in exactly one state. It can be either of:

• EMPTY, when the cell has no value (and is not in an illegal state). This is also the starting state for each cell.
• VALID_USER_VALUE, when the value in the cell is valid (1-9) and there is no conflict with any of the cell's neighbours.
• INVALID_USER_VALUE, when the value is invalid (i.e. everything except 1-9).
• COLLISION, when the value collides with (at least) one of its neigbours.
• ILLEGAL_STATE, when the cell is empty, but there are no remaining potential values, i.e. every valid value will collide with (at least) one neighbour.
• SINGLE_VALUE_LEFT, there is only one potential value left for the cell.
• UNIQUE_POTENTIAL_VALUE, if cell is empty and this is the only cell in a row/column/3-by-3 that has a specific potential value left.

### Statistics

A statistics table can be shown. The table shows information about how many cells that are in each state and the number of completed rows, columns and 3-by-3 squares.

## Settings

Configures what you will see on the Gameboard page. It can be tools for import/export, hints or statistics information.

### Show export

Show the current Sudoku puzzle as a matrix that can be saved. This matrix can then be reloaded/imported. The format for the matrix is a 9x9 matrix, where each cell is either the dot character or one of the integers 1-9.

Here are some examples of how an export matrix may look like (the import matrices have the same format):

The empty matrix:

......... ......... ......... ......... ......... ......... ......... ......... .........

A diagonal filled with values:

1........ .2....... ..3...... ...4..... ....5.... .....6... ......7.. .......8. ........9

One of the "difficult" puzzles found in Dagens Nyheter:

..9...2.. ...6..... .....24.. ..7..9... .654.3.2. .9..7...6 ..4...15. ......6.7 372....4.

A solved puzzle:

123456789 456789123 789123456 234567891 567891234 891234567 345678912 678912345 912345678

### Show import

Shows a textarea field where you can define a Sudoku puzzle to import. The format should be the same as for export (though the import matrix tool also supports zeroes instead of the dot characters, i.e. the row 1..4..7.9 is equal to 100400709).

NB! Make sure that there are no extra whitespaces in the matrix that you want to import and that the matrix consists of exactly nine rows.

### Show statistics

When checked, the statistics table with various information is shown.

### Show potential values

Show the numbers 1-9 for each cell, which are still potential values for the cell. With this option checked you will get support in bookkeeping which values remain for each cell.

### Show single value left

Indicates a cell with a specific background color, when there is only one potential value remaining. With this option checked you will be informed when there is only one possible value left for the cell (with respect to the values already present in the neighbour cells).

### Show unique potential value

Indicates one of the potential values remaining, with a specific background color, when it is a unique potential value.

## Examples

### Screenshots

Here you can see examples of some Gameboard states for a puzzle that can be solved by the hints given in the GUI. (This example is taken from "Dagens sudoku" in Metro 2015-06-16.)

The empty puzzle:

A starting state for the puzzle, where 27 values are defined for you (also showing 1 single value left and 7 unique potential values):

An intermediate state for the puzzle (showing 2 single values left and 6 unique potential values):

The solved puzzle:

## Technologies

HTML, AngularJS, Javascript and CSS are the technologies used for this implementation.

## Resources

The NNM Sudoku Magic is a spare time project developed by Anders Gustafson. I wanted to explore AngularJS and needed a problem to work with. So I came up with the idea that Sudoku is simple to understand, fun to work with and not (always) trivial to solve.

In May 2015 I started to implement the first version of NNM Sudoku Magic. The goal was to make a GUI that would support me in solving Sudoku problems. It should give hints for the "trivial" tasks searching for single values left (in row, column or 3-by-3 square) and unique potential values, so I quickly could come to the more interesting parts of solving Sudoku puzzles. The goal has never been to automatically solve the complete Sudoku puzzle, only to give these hints for the "trivial" parts.

### Version history

• Version 1.0, released 2015-06-15.

### Contact information

If you have any questions, comments, suggestions, errata, etc, the easiest way to contact me, is by sending an email to:

The sky is no limit!