All Projects → sfuhrm → sudoku

sfuhrm / sudoku

Licence: LGPL-3.0 license
A very fast Java Sudoku library implementation along with a command line client

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to sudoku

sudoku-solver
A simple sudoku solver
Stars: ✭ 16 (+6.67%)
Mutual labels:  sudoku-solver, sudoku, sudoku-solution-finder
python-sudoku-generator-solver
Python based sudoku generator that can create unique Sudoku board based on 4 difficulty levels. This code also includes a brute force sudoku solver that is capable of solving even the most difficult sudoku puzzles!
Stars: ✭ 58 (+286.67%)
Mutual labels:  sudoku-solver, sudoku, sudoku-generator
neuro-symbolic-sudoku-solver
⚙️ Solving sudoku using Deep Reinforcement learning in combination with powerful symbolic representations.
Stars: ✭ 60 (+300%)
Mutual labels:  sudoku-solver, sudoku
Resolvedor-de-Sudoku
Resolver Sudoku de genina.com
Stars: ✭ 17 (+13.33%)
Mutual labels:  sudoku-solver, sudoku
Sudoku-Solver
🎯 This Python-based Sudoku Solver utilizes the PyGame Library and Backtracking Algorithm to visualize and solve Sudoku puzzles efficiently. With its intuitive interface, users can input and interact with the Sudoku board, allowing for a seamless solving experience.
Stars: ✭ 51 (+240%)
Mutual labels:  sudoku-solver, sudoku
sudoLite
一款轻巧、趣萌、界面精美,具备统计、排行(即将推出),开源、免费、无广告的数独小程序
Stars: ✭ 55 (+266.67%)
Mutual labels:  sudoku, sudoku-generator
Hodoku
Hodoku is a solver/generator/trainer/analyzer for standard sudoku.
Stars: ✭ 49 (+226.67%)
Mutual labels:  sudoku
sudoku
Multiplayer concurrent sudoku. The winner is the player who fills the last cell correctly.
Stars: ✭ 15 (+0%)
Mutual labels:  sudoku
sudokufx
AR Sudoku grabber and solver using JavaCV, JavaFX and Scala
Stars: ✭ 64 (+326.67%)
Mutual labels:  sudoku
ConstraintSolver.jl
ConstraintSolver in Julia: Blog posts ->
Stars: ✭ 107 (+613.33%)
Mutual labels:  sudoku
xorpd-solutions
[SPOILER ALERT] My attempt at tackling the x86_64 asm riddles in xorpd's xchg rax,rax book. Pull requests welcome.
Stars: ✭ 57 (+280%)
Mutual labels:  riddle
sudoku
A Sudoku web app in React.
Stars: ✭ 50 (+233.33%)
Mutual labels:  sudoku
Sudoku
A sudoku solver using brute forces and logical techniques.
Stars: ✭ 49 (+226.67%)
Mutual labels:  sudoku
Udacity
This repo includes all the projects I have finished in the Udacity Nanodegree programs
Stars: ✭ 57 (+280%)
Mutual labels:  sudoku-solver
Sudoku
The classic game in its brand new, modern shape. Badges, points & leaderboards included.
Stars: ✭ 13 (-13.33%)
Mutual labels:  sudoku
go-sudoku
A web-based sudoku solver powered by OpenCV and Go
Stars: ✭ 17 (+13.33%)
Mutual labels:  sudoku-solver
Sudoku-Pattern-Generator-App
Android App for Generating Sudoku Number Pattern
Stars: ✭ 15 (+0%)
Mutual labels:  sudoku-generator
hsudoku
A native gtk sudoku game written in haskell
Stars: ✭ 31 (+106.67%)
Mutual labels:  sudoku
imgui
Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
Stars: ✭ 348 (+2220%)
Mutual labels:  sudoku
grilops
a GRId LOgic Puzzle Solver library
Stars: ✭ 29 (+93.33%)
Mutual labels:  sudoku-solver

Sudoku Java Library

Java CI with Maven Codacy Badge Coverage javadoc Maven Central ReleaseDate License: LGPL v3

A Java implementation of a very fast algorithm for creating Sudoku riddles. Has also the functionality to solve Sudoku riddles.

The following animation shows how quick the provided command line client can create Sudokus:

Creating a riddle

The riddles can be of the schema dimensions:

  • 4x4
  • 9x9 (standard size)
  • 16x16 (too slow at the moment)
  • 25x25 (too slow at the moment)

Building it

For building the application you need Apache Maven. Use the following command line:

$ mvn clean package

Features

In the following list I want to give an overview of the features:

  • Performance: Very fast algorithm that is using backtracking, but terminates in some fractions of a second. For fully filled boards this is usually less than 1ms on current hardware. For partly-filled riddles this is usually less than 20ms.
  • Pureness: Pure Java implementation without any runtime dependencies to other libraries. Runs on Java 8+.
  • Quality: High test coverage of >94%. Many (optional) runtime assertions to assure correct operation.
  • Output: Plain text, Markdown, LaTeX and JSON output formats. For an example, see 2000-sudokus.pdf, a collection of 2000 Sudokus.

Usage

You can review the javadoc for detailed information.

The usage for fully set Sudoku boards (no empty fields) is as following:


GameMatrix matrix = Creator.createFull();

You can create a solvable riddle (with empty fields) using


GameMatrix matrix = Creator.createFull(GameSchemas.SCHEMA_9X9);
Riddle riddle = Creator.createRiddle(matrix);

A solvable riddle looks like this:


. . 4 . . . . 2 9
. 2 . . . 4 . . .
6 . . . . . . . 3
2 4 . . . 3 . . .
5 . . . . . 9 . .
. 7 . 5 . . 8 . .
. . . . . 7 1 6 .
1 . . . . 6 . 9 .
. . . 4 . 2 . . 8

And last but not least you can solve a riddle using


    Riddle riddle = new GameMatrixFactory().newRiddle(GameSchemas.SCHEMA_9X9);
    riddle.setAll(QuadraticArrays.parse("000000000", ...));

    Solver solver = new Solver(riddle);
    List<GameMatrix> solutions = solver.solve();

For valid riddles you'll find in magazines there is only one solution in the list.

There is also a CLI client that demonstrates the usage of the library.

Including it in your projects

Please note that the current version is experimental. It creates and solves riddles. The API will change. The library could run into a runtime exception.

There are unit tests for many things, but the code is still young.

The recommended way of including the library into your project is using maven:


<dependency>
    <groupId>de.sfuhrm</groupId>
    <artifactId>sudoku</artifactId>
    <version>4.0.0</version>
</dependency>

Algorithm

The design idea is to use the narrowest bottleneck of the Sudoku board to prune the backtracking tree to the maximum and get the fastest results.

Initialization

The algorithm first fills three blocks with numbers in random order to reduce the amount of backtracking. After that, backtracking for the remaining fields starts.

Backtracking

The field with the least number of possible number candidates on the board is searched. All candidates are tried until the first candidate leads to a valid backtracking tree path. Backtracking occurs in this loop.

Note on algorithm optimization

It's enough to restrict each backtracking recursion to one field. This means there are no field-dead-ends, only value-dead-ends the algorithm runs in.

This can be proved because as long as the algorithms invariant to only add valid values is true, no fields become dead-ends. The requirement for field-dead-ends is that the surrounding fields have an illegal setup which leads to a rule-violation for each and every value of the field in question.

Versions

The version numbers are chosen according to the semantic versioning schema. Especially major version changes come with breaking API changes.

Author

Written 2017-2022 by Stephan Fuhrmann. You can reach me via email to s (at) sfuhrm.de

License

The project is licensed under LGPL 3.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].