Sudoku 1.1.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sudoku --version 1.1.6
                    
NuGet\Install-Package Sudoku -Version 1.1.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.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sudoku" Version="1.1.6" />
                    
Directory.Packages.props
<PackageReference Include="Sudoku" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sudoku --version 1.1.6
                    
#r "nuget: Sudoku, 1.1.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.
#addin nuget:?package=Sudoku&version=1.1.6
                    
Install as a Cake Addin
#tool nuget:?package=Sudoku&version=1.1.6
                    
Install as a Cake Tool

Sudoku

A fast Sudoku solver written in C#. Can also act as a Sudoku generator.

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.
*/

var solver = new Solver();

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.

/*
  There is an option to get the order in which the answer was found.
  This isn't generated by default for performance reasons.
*/

solver.Solve(puzzle, HistoryType.SolutionOnly);

foreach (var move in result.History)
{
    Console.WriteLine($"Row: {move.Y}    Column: {move.X}    Value: {move.Value}");        
}

/*
  Finally, there's an option to check whether the puzzle is a true Sudoku,
  that is, it only has 1 solution. Specify true as the third parameter
  to enable this (it is disabled by default for performance reasons).
*/

var result = solver.Solve(puzzle, HistoryType.SolutionOnly, true);

Console.WriteLine(result.Message);

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 │
 └───────┴───────┴───────┘    └───────┴───────┴───────┘

Generating Sudokus

var generator = new Generator();

var puzzle = generator.Generate(50); // Will remove 60 cells, leaving a puzzle with 31 clues. Anything under ~28 clues can take a while.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 257 5/4/2024
1.2.11 146 3/20/2024
1.2.10 120 3/20/2024
1.2.9 132 3/15/2024
1.2.7 143 3/14/2024
1.2.6 131 3/14/2024
1.2.5 150 3/14/2024
1.2.4 138 3/14/2024
1.2.3 150 3/13/2024
1.2.2 151 3/13/2024
1.2.1 149 3/12/2024
1.2.0 144 3/12/2024
1.1.6 154 3/12/2024
1.1.5 145 3/12/2024
1.1.4 130 3/12/2024
1.1.3 133 3/9/2024
1.1.2 150 3/9/2024
1.1.1 149 3/7/2024
1.1.0 149 3/7/2024
1.0.10 136 3/6/2024
1.0.9 130 3/6/2024
1.0.8 147 3/6/2024
1.0.4 153 3/6/2024
1.0.1 143 3/6/2024
1.0.0 124 3/6/2024