Skip to content

ThisTestUser/SudokuSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

SudokuSolver

A solver for many types of Sudokus.

How To Use

After importing the code to your IDE, head over to Main.java to add your problem to SUDOKU_PROBLEMS. You should create a new instance of SudokuProblem, which is initialized with a board as a 2D array of integers, and an instance of SudokuConstraints. That constructor accepts the Sudoku size and subsection dimensions. If there are any additional rules for the Sudoku, you will need to specify them also. Remember that in a 9x9 Sudoku, the cells range from 0-8.

Then compile and run the solver from the command line, using --problem <problem_id>, where the problem ID is a key in the SUDOKU_PROBLEMS map. The argument --displayalpha at the end is for converting numbers above 9 into letters.

Alternatively, add this program as a library to your own Java program and run Main.main(), after you've added the problem to SUDOKU_PROBLEMS in your program.

Special Note: If you have a SudokuXV and you have set sum5 and sum10, you should enable noSum5 and noSum10, as one of the rules in SudokuXV prohibits numbers next to each other from summing up to 5 or 10 if not marked. For consective sudokus, nonConsecutive should be enabled after consecutive is filled.

Features

  • Solve regular Sudokus and variants of Sudokus

  • Guaranteed to solve, if the Sudoku has a solution

  • Deterministic - For any input, will always output the same solution, even if there are multiple solutions

Downsides

  • Takes a long time to input custom rules - The Sudoku solver supports printing out rule templates from a text file of space separated numbers. Check ConstraintGenerator.java for the formatting. The command line format is --constraints-file <file_name> --mode <mode>.

  • Can't tell the user if there are multiple solutions

  • Not the best algorithm - This program uses brute force to solve the Sudoku. This doesn't affect most 9x9 Sudokus, which should all solve in a few minutes (it's an error if it doesn't). The only exception are Greater Than Sudokus with incomplete relations, which will not solve in a reasonable amount of time.

Also, anything above 9x9 is currently not viable.

For reference, this Sudoku below (Greater Than) took 2.5 minutes to solve with 9 clues provided. greaterthan

About

A solver for many types of Sudokus

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages