Saturday, November 16, 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).

 

- Advertisement -

 

Fig. 1: 6×6 matrix with non-numerics (unsolved and solved)

- Advertisement -
Fig. 4: 4×4 matrix with unsolved and solved puzzle

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

Fig. 5: 9×9 matrix solved puzzle

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).

Download Source Code: click here

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

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics