Sudoku 1.2.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Sudoku --version 1.2.6
NuGet\Install-Package Sudoku -Version 1.2.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sudoku" Version="1.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sudoku --version 1.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sudoku, 1.2.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sudoku as a Cake Addin #addin nuget:?package=Sudoku&version=1.2.6 // Install Sudoku as a Cake Tool #tool nuget:?package=Sudoku&version=1.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sudoku
A fast Sudoku solver written in C#. Can also act as a Sudoku generator.
Visualisations of Solving Process
Usage in Code
Solving Sudokus
var puzzle = new int[81];
/*
Fill the array with the puzzle here. Use 0 to represent empty cells.
Just flatten the puzzle into one long sequence,
so puzzle[0..8] is the first row, puzzle[9..17] is second and so on.
*/
/*
This is most performant.
If you want the solution steps, select HistoryType.SolutionOnly.
If you want all the steps attempted, select HistoryType.AllSteps.
If you want to check the puzzle has only 1 solution, specify SolveMethod.FindUnique.
If you want a count of the number of solutions, specify SolveMethod.FindAll.
*/
var solver = new Solver(HistoryType.None, SolveMethod.FindFirst);
var result = solver.Solve(puzzle);
/*
Output to console with a left offset of 1.
Store cursor y position to draw puzzle and solution side by side.
*/
var y = Console.CursorTop;
puzzle.DumpToConsole(1, y);
result.Solution.DumpToConsole(30, y);
// The result has additional informational properties.
result.Steps; // How many steps were explored to find the answer.
result.Microseconds; // How long it took to solve.
result.LogToConsole(); // Dump the steps taken to solve the puzzle.
foreach (var move in result.History)
{
Console.WriteLine($"Row: {move.Y} Column: {move.X} Value: {move.Value}");
}
Console.WriteLine(result.Message);
For an example of log output, see here.
Output:
┌───────┬───────┬───────┐ ┌───────┬───────┬───────┐
│ │ 2 │ 9 │ │ 4 5 7 │ 8 2 6 │ 1 9 3 │
│ 6 │ 1 │ │ │ 9 6 3 │ 1 4 5 │ 2 8 7 │
│ 2 │ 7 3 │ 6 │ │ 8 1 2 │ 7 3 9 │ 6 5 4 │
├───────┼───────┼───────┤ ├───────┼───────┼───────┤
│ 3 │ 4 │ 8 │ │ 2 3 1 │ 4 5 7 │ 8 6 9 │
│ 7 8 │ 6 9 │ │ │ 7 8 4 │ 6 9 1 │ 3 2 5 │
│ │ │ 4 │ │ 6 9 5 │ 2 8 3 │ 7 4 1 │
├───────┼───────┼───────┤ ├───────┼───────┼───────┤
│ 8 │ │ │ │ 1 7 8 │ 9 6 4 │ 5 3 2 │
│ 9 │ │ 1 │ │ 5 2 9 │ 3 7 8 │ 4 1 6 │
│ │ 5 │ 8 │ │ 3 4 6 │ 5 1 2 │ 9 7 8 │
└───────┴───────┴───────┘ └───────┴───────┴───────┘
Solved
Generating Sudokus
var generator = new Generator();
var puzzle = generator.Generate(30); // Will generate a puzzle with 30 clues. Can get quite slow below 25.
puzzle.DumpToConsole(1);
Output:
┌───────┬───────┬───────┐
│ 6 │ 4 │ 2 8 │
│ │ 8 9 │ 6 │
│ 9 5 │ │ │
├───────┼───────┼───────┤
│ 5 │ │ │
│ 6 4 │ │ │
│ 8 │ 4 2 │ 7 3 │
├───────┼───────┼───────┤
│ 6 │ │ 7 │
│ │ │ 4 8 │
│ │ │ │
└───────┴───────┴───────┘
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.12 | 226 | 5/4/2024 |
1.2.11 | 125 | 3/20/2024 |
1.2.10 | 103 | 3/20/2024 |
1.2.9 | 112 | 3/15/2024 |
1.2.7 | 125 | 3/14/2024 |
1.2.6 | 113 | 3/14/2024 |
1.2.5 | 131 | 3/14/2024 |
1.2.4 | 121 | 3/14/2024 |
1.2.3 | 128 | 3/13/2024 |
1.2.2 | 131 | 3/13/2024 |
1.2.1 | 130 | 3/12/2024 |
1.2.0 | 124 | 3/12/2024 |
1.1.6 | 136 | 3/12/2024 |
1.1.5 | 123 | 3/12/2024 |
1.1.4 | 113 | 3/12/2024 |
1.1.3 | 116 | 3/9/2024 |
1.1.2 | 131 | 3/9/2024 |
1.1.1 | 130 | 3/7/2024 |
1.1.0 | 130 | 3/7/2024 |
1.0.10 | 119 | 3/6/2024 |
1.0.9 | 112 | 3/6/2024 |
1.0.8 | 132 | 3/6/2024 |
1.0.4 | 131 | 3/6/2024 |
1.0.1 | 123 | 3/6/2024 |
1.0.0 | 104 | 3/6/2024 |