Skip to content

Apply common sudoku solving techniques to find the next step in a sudoku.

License

Notifications You must be signed in to change notification settings

raphael-kahler/SudokuSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Solver

A solver for Sudoku puzzles that uses common solving techniques. The solver shows for every step which technique was used, so you can follow along how the puzzle was solved. You can use this for learning techniques or to get a hint for the Sudoku you are stuck on.

Website

Try out the Sudoku solver on xwingsudoku.com.

xwingsudoku Solver Website Screenshot

The website is implemented using Blazor Webassembly, which allows running c# code on the client side in the browser without a backend server.

Techniques

The following techniques are implemented so far. Each technique can individually be added to the solver.

Technique Usage
Basic Techniques
Each value can only appear once per row/column/box. Technique.EliminationByValue.AllDirections()
Subset Techniques
Naked Single Technique.Subsets.NakedSingle()
Naked Pair Technique.Subsets.NakedPairs()
Naked Triple Technique.Subsets.NakedTriples()
Naked Quad Technique.Subsets.NakedQuads()
Hidden Single Technique.Subsets.HiddenSingles()
Hidden Pair Technique.Subsets.HiddenPairs()
Hidden Triple Technique.Subsets.HiddenTriples()
Hidden Quad Technique.Subsets.HiddenQuads()
Intersection Techniques
Locked Candidates Pointing Technique.LockedCandidates.Pointing.AllDirections()
Locked Candidates Claiming Technique.LockedCandidates.Claiming.AllDirections()
Coloring Techniques
Simple Coloring Technique.Colors.SimpleColoring()
Fish Techniques
2-Fish: X-Wing, Finned X-Wing, Sashimi X-Wing Technique.Fish.XWing()
3-Fish: SwordFish, Finned Swordfish, Sashimi Swordfish Technique.Fish.Swordfish()
4-Fish: Jellyfish, Finned Jellyfish, Sashimi Jellyfish Technique.Fish.Jellyfish()
Wing Techniques
XY-Wing Technique.Wings.XyWing()
XYZ-Wing Technique.Wings.XyzWing()
WXYZ-Wing Technique.Wings.WxyzWing()

Commandline tool

The Sudoku solver library is also utilized in a simple console application, which can be run to quickly solve a single step or an entire Sudoku.

Console Output Example

Usage

Install .NET 5 SDK or newer to be able to build the projects.

Running the website locally

cd src/Site
dotnet run

Then browse the site locally at https://localhost:5001.

Running the commandline tool

cd src/SudokuConsole
dotnet build

To solve a Sudoku completely, just provide the path to a Sudoku input file.

./bin/Debug/net5.0/SudokuConsole.exe -i ../../inputs/sudoku-basic1.txt

To solve only the next step of an in-progress sudoku, you can use the --nextStep flag.

./bin/Debug/net5.0/SudokuConsole.exe -i ../../inputs/withCandidates/sudoku-evil1.txt --nextStep