TheAlgorithms / Java

All Algorithms implemented in Java
MIT License
60.21k stars 19.47k forks source link

Implement Sudoku Solver #3634

Closed Phantom-Sixth-Man closed 2 years ago

Phantom-Sixth-Man commented 2 years ago

Is your feature request related to a problem? Please describe. Write a program to solve a Sudoku puzzle by filling the empty cells.

Describe the solution you'd like A sudoku solution must satisfy all of the following rules:

Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid. The '.' character indicates empty cells.

See below example:

Input: board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]
Output: [["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"],["1","9","8","3","4","2","5","6","7"],["8","5","9","7","6","1","4","2","3"],["4","2","6","8","5","3","7","9","1"],["7","1","3","9","2","4","8","5","6"],["9","6","1","5","3","7","2","8","4"],["2","8","7","4","1","9","6","3","5"],["3","4","5","2","8","6","1","7","9"]]

Additional context Need Optimized solution

redhairrs commented 2 years ago

I have already done this kind of problem using recursion and backtracking so if u can assign this task to me I can do it.

skyamit commented 2 years ago

I have already implemented the sudoku solver, please find the PR with Solution (soduku-solver)

chandraPrakash23 commented 2 years ago

I have already implemented the optimized suduko solver code using backtracking and recursion, so you can assign this task to me.

Mehrotra01 commented 2 years ago

As being a problem solver .I'm a bit fluent in solving these kind of problems, i would be very gratefull if you asssign this task to me

siriak commented 2 years ago

Already implemented here https://github.com/TheAlgorithms/Java/blob/e96f567bfc6e980dc5c4c48ccf185d7f7c7108ab/src/main/java/com/thealgorithms/others/Sudoku.java