Welcome to my Sudoku solver! This repository includes:
- Methods for computing the solution of a sudoku board
- Methods for generating a sudoku board with a unique solution
- Simple web application available for those who would like to interact with the Sudoku solver from a more user friendly interface.
The sudoku solver has a frontend web application that can easily be setup locally. From the repository folder, run:
make compose-docker
Note that, it is required to have Docker
installed on your computer. When successfully setup, the frontend application will be hosted on http://localhost:8080/ and backend server will be hosted on http://localhost:5000/.
In the repository folder, run:
cd core/ && make setup
In the terminal, simply use the command solve
followed by an input filepath. Note that the input file must have .txt format with whitespace as separator. For example:
0 0 9 0 0 0 4 6 3
0 0 6 3 4 0 5 2 9
2 3 4 5 6 9 7 1 8
0 6 7 0 0 0 3 4 1
0 4 0 0 3 0 2 9 5
0 2 0 0 0 0 6 8 0
0 0 2 0 0 1 9 3 4
4 9 3 8 2 5 1 7 6
0 7 0 4 9 3 8 5 2
where 0 represents empty cells, see also SudokuSolver/core/boards
for examples. Given an input file, you can compute a solution by using the solve
command. For example:
solve core/boards/board_1.txt
It is also possible to execute solve
iteratively over multiple input files:
solve core/boards/board_1.txt core/boards/board_2.txt core/boards/board_3.txt
In any Python interactives, simply execute the following command:
import numpy as np
from sudoku.solver import SudokuSolver
board = np.array(
[[0, 0, 9, 0, 0, 0, 4, 6, 3],
[0, 0, 6, 3, 4, 0, 5, 2, 9],
[2, 3, 4, 5, 6, 9, 7, 1, 8],
[0, 6, 7, 0, 0, 0, 3, 4, 1],
[0, 4, 0, 0, 3, 0, 2, 9, 5],
[0, 2, 0, 0, 0, 0, 6, 8, 0],
[0, 0, 2, 0, 0, 1, 9, 3, 4],
[4, 9, 3, 8, 2, 5, 1, 7, 6],
[0, 7, 0, 4, 9, 3, 8, 5, 2]], dtype=int)
solver = SudokuSolver(board=board)
solver.run()
If it is desired to load the Sudoku board from a .txt-file use:
from sudoku.solver import SudokuSolver
solver = SudokuSolver.from_txt('core/boards/board_1.txt')
solver.run()