npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@forfuns/sudoku

v1.2.2

Published

sudoku solver and generator

Downloads

29

Readme

@forfuns/sudoku

关于 about

codebeat badge npm version License License Page Views Count

一款基于javascript / nodejs 开源的数独 计算器生成器 依赖库

opensource sudoku solver and generator with javascript/nodejs library

功能 features

  • [√] 完整数独解题器 - complete Sudoku solver
  • [√] 题目生成功能 - random one-solution generator with five level

安装 install

npm i @forfuns/sudoku

使用 tutorial

Solver & Generator

// Solver
// 9 * 9 矩阵数独题目,-1值为待输入值
// 9 * 9 matrix for the puzzle , -1 mean input position
let puzzle = [
    -1,-1,8,    9,-1,6,     -1,-1,5,
    -1,4,3,     -1,-1,-1,   -1,2,-1,
    -1,-1,-1,   -1,-1,-1,   -1,-1,-1,

    -1,-1,4,    -1,-1,-1,   9,-1,-1,
    5,-1,-1,    -1,4,-1,    6,8,-1,
    -1,-1,-1,   1,-1,-1,    -1,-1,-1,

    2,-1,-1,    -1,8,-1,    -1,7,-1,
    -1,-1,-1,   -1,3,4,     1,-1,-1,
    -1,6,-1,    -1,-1,9,    -1,-1,-1,
]
const { Sudoku , generator } = require('@forfuns/sudoku')

let sudoku 
// 数独解题(不区分是否唯一数独,回溯出结果直接返回)
// solve sudoku with puzzle
sudoku = new Sudoku(puzzle)

// 数独解题 只能计算唯一解的数独,如果该puzzle拥有多解,则抛出错误Error('puzzle is not one-solution sudoku')
// 一般来说,只是单纯解题,使用上面的构造器即可,速度最快
// if you need to sure puzzle is one solution or not , you can use strict=true (default is false), that will take longer
// if puzzle is not one solution sudoku , will throw Error('puzzle is not one-solution sudoku')
sudoku = new Sudoku(puzzle, true) 

// 获取原题目
// get sudoku puzzle
sudoku.getPuzzle()

// 获取完整答案
// get sudoku solution
sudoku.getSolution()

// 查看debug信息
// show debug infomation
sudoku.debug()

-----------------------------------------------------------------------------
// Generator
// 数独题目生成
// make puzzle with generate function , four level 0:easy / 1:medium / 2:hard / 3:expert / 4:hell(that may take long times)
puzzle = generator(0) // level 可选 0 ~ 4 分别代表:简单 / 中等 / 困难 / 专家 / "地狱"

相关测试用例,请查看 /test/sudoku/*.js

npm run test-solver
npm run test-generator

with any idea welcome open issue to make me know

if you want same project with other language like go / dart and flutter app , here they are :