Wednesday, August 7, 2024

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages

# JavaScript-based Multiformat Sudoku Puzzle Solver

Sudoku is a mathematical-cum-logical puzzle where every digit should come uniquely in every row and column without repetition. We generally find Sudoku puzzles in dailies and magazines with various levels of toughness with respect to placement of numbers, number of puzzle digits and blanks.

Mostly, dailies publish only numerical puzzles with limited matrix length of either 9Ã—9 or 6Ã—6. In this project, we show that non-numeric entities can also be used to form a Sudoku grid. One can also define the size of the matrix beyond 6Ã—6 and 9Ã—9. In this project one can use numeric digits from 1-9, and alphabets in upper and lower cases (A-Z, a-z).

The 6Ã—6 matrix with non-numerics is shown in Fig. 1. Likewise, one can have a one-cell grid of 1Ã—1 size to 2401-celled grid of 7Ã—7 size with the above characters.

There are two programs for this project: sudo_alpha.html and sudo_num.html. The first code is for solving the alphabet-based Sudoku puzzle and the later code is for numeric-based Sudoku puzzle.

In both case, the default size of the matrix is 3Ã—3, which is a 9Ã—9 matrix having 81-cell grids. User can change the size from 1Ã—1 up to 7Ã—7 as per requirement.

The program

The program is coded in JavaScript and when launched using Internet Explorer, it displays a grid with predefined numbers in each of the cells. The first cell represents the rows, and the second cell represents columns. The rows and columns of the cells define the size of the matrix.

Case 1: When â€˜2â€™ is input in the first cell (column) and â€˜3â€™ is input in the second cell (row), a 6Ã—6 matrix with two columns and three rows is generated, which is colour-coded to differentiate between the distinct cell grids (refer Fig. 2).

Case 2: When â€˜3â€™ is input in the first cell (column) and â€˜2â€™ is input in the second cell (row), a 6Ã—6 matrix with three columns and two rows is generated, which is colour-coded to differentiate between the distinct cell grids (refer Fig. 3).

One more characteristic feature of this program is its artificial intelligence type solving ability that mimics human thinking in solving this puzzle. Please note that it does not use any fuzzy logic in the backend but only JavaScript to attain this. Moreover, the program can only solve logically valid puzzles. If more cells are filled in a puzzle, it takes less time to solve the puzzle, and vice-versa. It can generate either symmetric or asymmetric puzzles, as per your requirement, i.e., it can generate 1Ã—1, 9Ã—9, or 1Ã—2, 8Ã—9 and 34Ã—35 matrices or any other matrix up to 35Ã—35. 4Ã—4 matrix and 9Ã—9 solved puzzles are shown in Figs 4 and 5, respectively.

The author, a B.Tech in electronics and communications engineering, likes coding and has keen interest in space technology (satellite communications) and mobile communication