dokusan


Namedokusan JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummarySudoku generator and solver with a step-by-step guidance
upload_time2023-04-08 17:22:16
maintainer
docs_urlNone
authorAleksei Maslakov
requires_python>=3.8,<4.0
licenseGPL-3.0
keywords sudoku sudoku-solver sudoku-generator solver generator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========
Overview
========

.. start-badges

.. image:: https://github.com/unmade/dokusan/workflows/Lint%20and%20tests/badge.svg
    :alt: Build Status
    :target: https://github.com/unmade/dokusan/blob/master/.github/workflows/lint-and-tests.yml

.. image:: https://codecov.io/gh/unmade/dokusan/branch/master/graph/badge.svg
    :alt: Coverage Status
    :target: https://codecov.io/gh/unmade/dokusan

.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
    :alt: Checked with mypy
    :target: http://mypy-lang.org/

.. image:: https://img.shields.io/pypi/v/dokusan.svg
    :alt: PyPI Package latest release
    :target: https://pypi.org/project/dokusan

.. image:: https://img.shields.io/pypi/wheel/dokusan.svg
    :alt: PyPI Wheel
    :target: https://pypi.org/project/dokusan

.. image:: https://img.shields.io/pypi/pyversions/dokusan.svg
    :alt: Supported versions
    :target: https://pypi.org/project/dokusan

.. image:: https://img.shields.io/badge/License-GPLv3-purple.svg
    :alt: GPLv3 License
    :target: https://github.com/unmade/dokusan/blob/master/LICENSE

.. end-badges

Sudoku generator and solver with a step-by-step guidance

Installation
============

.. code-block:: bash

    pip install dokusan

Quickstart
==========

Sudoku Solvers
--------------

Step-by-step solver
*******************

This solver tries to solve sudoku using human-like strategies.
Currently following techniques are supported:

- Naked/Hidden singles
- Naked Pairs/Triplets
- Locked Candidate
- XY-Wing
- Unique Rectangle

For example to see all techniques that sudoku has:

.. code-block:: python

    from dokusan import solvers
    from dokusan.boards import BoxSize, Sudoku


    sudoku = Sudoku.from_list(
        [
            [0, 0, 0, 0, 9, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 2, 3, 0, 0],
            [0, 0, 7, 0, 0, 1, 8, 2, 5],
            [6, 0, 4, 0, 3, 8, 9, 0, 0],
            [8, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 9, 0, 0, 0, 0, 0, 8],
            [1, 7, 0, 0, 0, 0, 6, 0, 0],
            [9, 0, 0, 0, 1, 0, 7, 4, 3],
            [4, 0, 3, 0, 6, 0, 0, 0, 1],
        ],
        box_size=BoxSize(3, 3),
    )

    {step.combination.name for step in solvers.steps(sudoku)}

Backtracking-based solver
*************************

This solver is based on backtracking algorithm,
however slightly modified to work fast

.. code-block:: python

    from dokusan import solvers, renderers
    from dokusan.boards import BoxSize, Sudoku


    sudoku = Sudoku.from_list(
        [
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 3, 0, 8, 5],
            [0, 0, 1, 0, 2, 0, 0, 0, 0],
            [0, 0, 0, 5, 0, 7, 0, 0, 0],
            [0, 0, 4, 0, 0, 0, 1, 0, 0],
            [0, 9, 0, 0, 0, 0, 0, 0, 0],
            [5, 0, 0, 0, 0, 0, 0, 7, 3],
            [0, 0, 2, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 4, 0, 0, 0, 9],
        ],
        box_size=BoxSize(3, 3),
    )

    solution = solvers.backtrack(sudoku)
    print(renderers.colorful(solution))

Sudoku Generator
----------------

Generator algorithm is mainly based on
`article <https://dlbeer.co.nz/articles/sudoku.html>`_ by Daniel Beer.
The average time to generate Sudoku with rank of 150 is 700ms.

To generate a new sudoku:

.. code-block:: python

    from dokusan import generators, renderers


    sudoku = generators.random_sudoku(avg_rank=150)
    print(renderers.colorful(sudoku))

Ranking and Sudoku difficulty
*****************************

``avg_rank`` option roughly defines the difficulty of the sudoku.
Sudoku with rank lower than 100 contains only naked/hidden singles.
Sudoku with rank greater than 150 contains
Naked Subsets/Locked Candidate/XY Wing/etc...,
however this is not always guaranteed.

For higher ranks it is also not guaranteed that generated Sudoku rank
will be higher than provided ``avg_rank``,
so to ensure sudoku has desired rank one can do the following:

.. code-block:: python

    from dokusan import generators, stats


    avg_rank = 450
    while stats.rank(sudoku := generators.random_sudoku(avg_rank)) < avg_rank:
        continue

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "dokusan",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "sudoku,sudoku-solver,sudoku-generator,solver,generator",
    "author": "Aleksei Maslakov",
    "author_email": "lesha.maslakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/53/9b/0c8f048f30d5bbf822c3337d4cd5ed8f75607f03588fdb4cade8cddcd162/dokusan-0.1.0.tar.gz",
    "platform": null,
    "description": "========\nOverview\n========\n\n.. start-badges\n\n.. image:: https://github.com/unmade/dokusan/workflows/Lint%20and%20tests/badge.svg\n    :alt: Build Status\n    :target: https://github.com/unmade/dokusan/blob/master/.github/workflows/lint-and-tests.yml\n\n.. image:: https://codecov.io/gh/unmade/dokusan/branch/master/graph/badge.svg\n    :alt: Coverage Status\n    :target: https://codecov.io/gh/unmade/dokusan\n\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\n    :alt: Checked with mypy\n    :target: http://mypy-lang.org/\n\n.. image:: https://img.shields.io/pypi/v/dokusan.svg\n    :alt: PyPI Package latest release\n    :target: https://pypi.org/project/dokusan\n\n.. image:: https://img.shields.io/pypi/wheel/dokusan.svg\n    :alt: PyPI Wheel\n    :target: https://pypi.org/project/dokusan\n\n.. image:: https://img.shields.io/pypi/pyversions/dokusan.svg\n    :alt: Supported versions\n    :target: https://pypi.org/project/dokusan\n\n.. image:: https://img.shields.io/badge/License-GPLv3-purple.svg\n    :alt: GPLv3 License\n    :target: https://github.com/unmade/dokusan/blob/master/LICENSE\n\n.. end-badges\n\nSudoku generator and solver with a step-by-step guidance\n\nInstallation\n============\n\n.. code-block:: bash\n\n    pip install dokusan\n\nQuickstart\n==========\n\nSudoku Solvers\n--------------\n\nStep-by-step solver\n*******************\n\nThis solver tries to solve sudoku using human-like strategies.\nCurrently following techniques are supported:\n\n- Naked/Hidden singles\n- Naked Pairs/Triplets\n- Locked Candidate\n- XY-Wing\n- Unique Rectangle\n\nFor example to see all techniques that sudoku has:\n\n.. code-block:: python\n\n    from dokusan import solvers\n    from dokusan.boards import BoxSize, Sudoku\n\n\n    sudoku = Sudoku.from_list(\n        [\n            [0, 0, 0, 0, 9, 0, 1, 0, 0],\n            [0, 0, 0, 0, 0, 2, 3, 0, 0],\n            [0, 0, 7, 0, 0, 1, 8, 2, 5],\n            [6, 0, 4, 0, 3, 8, 9, 0, 0],\n            [8, 1, 0, 0, 0, 0, 0, 0, 0],\n            [0, 0, 9, 0, 0, 0, 0, 0, 8],\n            [1, 7, 0, 0, 0, 0, 6, 0, 0],\n            [9, 0, 0, 0, 1, 0, 7, 4, 3],\n            [4, 0, 3, 0, 6, 0, 0, 0, 1],\n        ],\n        box_size=BoxSize(3, 3),\n    )\n\n    {step.combination.name for step in solvers.steps(sudoku)}\n\nBacktracking-based solver\n*************************\n\nThis solver is based on backtracking algorithm,\nhowever slightly modified to work fast\n\n.. code-block:: python\n\n    from dokusan import solvers, renderers\n    from dokusan.boards import BoxSize, Sudoku\n\n\n    sudoku = Sudoku.from_list(\n        [\n            [0, 0, 0, 0, 0, 0, 0, 0, 0],\n            [0, 0, 0, 0, 0, 3, 0, 8, 5],\n            [0, 0, 1, 0, 2, 0, 0, 0, 0],\n            [0, 0, 0, 5, 0, 7, 0, 0, 0],\n            [0, 0, 4, 0, 0, 0, 1, 0, 0],\n            [0, 9, 0, 0, 0, 0, 0, 0, 0],\n            [5, 0, 0, 0, 0, 0, 0, 7, 3],\n            [0, 0, 2, 0, 1, 0, 0, 0, 0],\n            [0, 0, 0, 0, 4, 0, 0, 0, 9],\n        ],\n        box_size=BoxSize(3, 3),\n    )\n\n    solution = solvers.backtrack(sudoku)\n    print(renderers.colorful(solution))\n\nSudoku Generator\n----------------\n\nGenerator algorithm is mainly based on\n`article <https://dlbeer.co.nz/articles/sudoku.html>`_ by Daniel Beer.\nThe average time to generate Sudoku with rank of 150 is 700ms.\n\nTo generate a new sudoku:\n\n.. code-block:: python\n\n    from dokusan import generators, renderers\n\n\n    sudoku = generators.random_sudoku(avg_rank=150)\n    print(renderers.colorful(sudoku))\n\nRanking and Sudoku difficulty\n*****************************\n\n``avg_rank`` option roughly defines the difficulty of the sudoku.\nSudoku with rank lower than 100 contains only naked/hidden singles.\nSudoku with rank greater than 150 contains\nNaked Subsets/Locked Candidate/XY Wing/etc...,\nhowever this is not always guaranteed.\n\nFor higher ranks it is also not guaranteed that generated Sudoku rank\nwill be higher than provided ``avg_rank``,\nso to ensure sudoku has desired rank one can do the following:\n\n.. code-block:: python\n\n    from dokusan import generators, stats\n\n\n    avg_rank = 450\n    while stats.rank(sudoku := generators.random_sudoku(avg_rank)) < avg_rank:\n        continue\n",
    "bugtrack_url": null,
    "license": "GPL-3.0",
    "summary": "Sudoku generator and solver with a step-by-step guidance",
    "version": "0.1.0",
    "split_keywords": [
        "sudoku",
        "sudoku-solver",
        "sudoku-generator",
        "solver",
        "generator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63aeb3ed699da71ac18d2d578725980d87be1b4fbc973cfa548e4c0968c2efd3",
                "md5": "a62fb104e82479010c5dd8b9137795b6",
                "sha256": "cddb3456de83e1af430191fcb7e8f25b86eb1a36103f535de01c0c0331f5baaa"
            },
            "downloads": -1,
            "filename": "dokusan-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a62fb104e82479010c5dd8b9137795b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 22669,
            "upload_time": "2023-04-08T17:22:13",
            "upload_time_iso_8601": "2023-04-08T17:22:13.598490Z",
            "url": "https://files.pythonhosted.org/packages/63/ae/b3ed699da71ac18d2d578725980d87be1b4fbc973cfa548e4c0968c2efd3/dokusan-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "539b0c8f048f30d5bbf822c3337d4cd5ed8f75607f03588fdb4cade8cddcd162",
                "md5": "c339e89720b44ed5b93bb9219f81eff3",
                "sha256": "b504846e560e9fcddf99ed8bd38dab86f8d99a0c5f270cd2bea2c79347a6cd8b"
            },
            "downloads": -1,
            "filename": "dokusan-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c339e89720b44ed5b93bb9219f81eff3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 21518,
            "upload_time": "2023-04-08T17:22:16",
            "upload_time_iso_8601": "2023-04-08T17:22:16.567405Z",
            "url": "https://files.pythonhosted.org/packages/53/9b/0c8f048f30d5bbf822c3337d4cd5ed8f75607f03588fdb4cade8cddcd162/dokusan-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-08 17:22:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "dokusan"
}
        
Elapsed time: 0.06105s