Sudoku 1.2.12

dotnet add package Sudoku --version 1.2.12
NuGet\Install-Package Sudoku -Version 1.2.12
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.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sudoku --version 1.2.12
#r "nuget: Sudoku, 1.2.12"
#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.12

// Install Sudoku as a Cake Tool
#tool nuget:?package=Sudoku&version=1.2.12

Sudoku

A fast Sudoku solver written in C#. Can also act as a Sudoku generator. https://github.com/stevehjohn/Sudoku

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.
   - all the steps attempted, select HistoryType.AllSteps.
   - to check the puzzle has only 1 solution, specify SolveMethod.FindUnique.
   - 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 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 100 5/4/2024
1.2.11 102 3/20/2024
1.2.10 80 3/20/2024
1.2.9 87 3/15/2024
1.2.7 96 3/14/2024
1.2.6 87 3/14/2024
1.2.5 88 3/14/2024
1.2.4 96 3/14/2024
1.2.3 100 3/13/2024
1.2.2 89 3/13/2024
1.2.1 100 3/12/2024
1.2.0 99 3/12/2024
1.1.6 106 3/12/2024
1.1.5 101 3/12/2024
1.1.4 87 3/12/2024
1.1.3 103 3/9/2024
1.1.2 103 3/9/2024
1.1.1 102 3/7/2024
1.1.0 102 3/7/2024
1.0.10 93 3/6/2024
1.0.9 87 3/6/2024
1.0.8 98 3/6/2024
1.0.4 104 3/6/2024
1.0.1 99 3/6/2024
1.0.0 82 3/6/2024