Giter Club home page Giter Club logo

komeilmehranfar / sudoku-core Goto Github PK

View Code? Open in Web Editor NEW
92.0 2.0 3.0 3.3 MB

A typescript Sudoku package for generating, solving (step-by-step or all), and analyzing Sudoku boards with ease. Perfect for building Sudoku games and integrating Sudoku functionality into your applications.

Home Page: https://www.npmjs.com/package/sudoku-core

License: MIT License

JavaScript 4.22% Shell 0.60% TypeScript 95.18%
sudoku sudoku-game sudoku-generator sudoku-puzzle sudoku-solver sudoku-js sudoku-analyze sudoku-ts sudoku-board sudoku-checker

sudoku-core's Introduction

A typescript Sudoku package for generating, solving (step-by-step or all), and analyzing Sudoku boards with ease. Perfect for building Sudoku games and integrating Sudoku functionality into your applications.

Logo

Sudoku Solver and Generator Javascript

Explore the docs »

View Demo . Report Bug . Request Feature

Downloads Contributors Forks Stargazers Issues License

Table Of Contents

About the package

gzipped size: 3.2k

Key Features:

Board Generation: Quickly create Sudoku boards for various difficulty levels.

Solver: Solve Sudoku puzzles.

Step-by-Step Solution: Walk through the solution process step by step, making it ideal for educational purposes or enhancing user engagement in Sudoku apps.

Board Analysis: Analyze the difficulty and strategies to solve a sudoku board.

Getting Started

Installation

npm install sudoku-core@latest

Usage

function Input Output
generate "easy" | "medium" | "hard" | "expert" | "master" Board
solve Board SolvingResult
hint Board SolvingResult
analyze Board AnalyzeData

board:

  • it has numbers from 1-9 or null
  • it has 81 cells
  • it's solvable (not by brute force)
  • there is only one version of answer to this board (not the process, the result) [1,null,9,5,8,null,null,6,3, ... 81 items]

generate

  • Generates a new Sudoku puzzle.
// difficulty: easy - medium - hard - expert - master;
const board = generate("easy");
console.log(board);
[
  1,
  null,
  9,
  5,
  8,
  null,
  null,
  6,
  3
  //... 81 items
]

solve

  • Solves the entire puzzle.
const solvedBoard = solve(board);
console.log(solvedBoard);
{
  "solved": true,
  "board": [
    2,
    7,
    6,
    3,
    8,
    1,
    9
    // ... 81 items
  ],
  "steps": [
    {
      "strategy": "Single Candidate Strategy",
      "updates": [{
        "index": 5,
        "filledValue": 1,
        "eliminatedCandidate": null,
      }],
      "type": "value"
    },
    ...steps
  ],
  "analysis": {
    "hasSolution": true,
    "hasUniqueSolution": true,
    "usedStrategies": [
      { "title": "Single Remaining Cell Strategy", "frequency": 21 },
      ...strategies
    ],
    "difficulty": "master",
    "score": 2232
  }
}

hint

  • Solves the next step of the puzzle and return steps.
const solvedBoard = hint(board);
console.log(solvedBoard);
{
  "solved": true,
  "board": [
    null,
    7,
    6,
    null,
    null,
    1, // null => 1
    null
    // ... 81 items
  ],
  "steps": [
    {
      "strategy": "Single Candidate Strategy",
      "updates": [{
        "index": 5,
        "filledValue": 1,
        "eliminatedCandidate": null,
      }],
      "type": "value"
    }
  ],
  "analysis": {
    "hasSolution": true,
    "hasUniqueSolution": true,
    "usedStrategies": [
      { "title": "Single Remaining Cell Strategy", "frequency": 21 },
      ...strategies
    ],
    "difficulty": "master",
    "score": 2232
  }
}

analyze

  • Returns an analysis of the current board state.
const analyzeData = analyze(board);
console.log(analyzeData);
{
  "hasSolution": true,
  "hasUniqueSolution": true,
  "usedStrategies": [
    { "title": "Single Remaining Cell Strategy", "frequency": 21 },
    { "title": "Single Candidate Cell Strategy", "frequency": 11 },
    { "title": "Single Candidate Value Strategy", "frequency": 29 },
    { "title": "Pointing Elimination Strategy", "frequency": 27 }
  ],
  "level": "expert",
  "score": 1683.1
}

Project Stats

Alt

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  • If you have suggestions for adding or removing projects, feel free to open an issue to discuss it, or directly create a pull request after you edit the README.md file with necessary changes.
  • Please make sure you check your spelling and grammar.
  • Create individual PR for each suggestion.

Creating A Pull Request

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Authors

Acknowledgements

References

sudoku-core's People

Contributors

komeilmehranfar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sudoku-core's Issues

Async calls

Hi, are there any plans to make the "generate" method asynchronous? It can block the UI up to 10 seconds if computed in the front-end. Thank you.

Question about commented code and strategies

Hey, thank you for the project, it implements many human strategies and is very handy for learning and defining difficulties.

I'm just curious about the commented code, mostly dealing with different strategies. Why? What's wrong with them?

I also heard about several more advanced strategies (XWing, Swordfish, Jellyfish, XYWing, XYZWing). What about them?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.