Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/0x-jerry/sudoku

数独生成 & 计算 算法
https://github.com/0x-jerry/sudoku

sudoku sudoku-generator sudoku-solver

Last synced: about 2 months ago
JSON representation

数独生成 & 计算 算法

Awesome Lists containing this project

README

        

# 数独 (Sudoku)

Generator

```js
const sudoku = new Sudoku()

sudoku.generate()

console.log(sudoku.toString(), sudoku.validate())
// 2 1 8 | 3 5 7 | 9 6 4
// 9 6 4 | 8 1 2 | 5 7 3
// 3 7 5 | 9 4 6 | 8 2 1
// ---------------------
// 4 3 2 | 6 7 8 | 1 9 5
// 8 5 7 | 2 9 1 | 4 3 6
// 6 9 1 | 5 3 4 | 7 8 2
// ---------------------
// 1 4 6 | 7 2 9 | 3 5 8
// 5 2 9 | 1 8 3 | 6 4 7
// 7 8 3 | 4 6 5 | 2 1 9
```

Resolver

```js
const sudoku = new Sudoku()

const source = `2 1 0 3 5 7 9 6 4
0 0 0 8 1 2 5 0 3
3 0 5 9 4 6 0 2 1
0 3 2 6 7 0 1 9 5
8 5 7 2 9 0 4 3 6
6 9 1 5 0 4 7 8 2
1 4 6 0 2 9 3 5 8
5 2 9 1 8 3 6 4 7
7 8 3 4 6 5 0 1 9
`

sudoku.resolve(source)
console.log(sudoku.toString(), sudoku.validate())
// 2 1 8 | 3 5 7 | 9 6 4
// 9 6 4 | 8 1 2 | 5 7 3
// 3 7 5 | 9 4 6 | 8 2 1
// ---------------------
// 4 3 2 | 6 7 8 | 1 9 5
// 8 5 7 | 2 9 1 | 4 3 6
// 6 9 1 | 5 3 4 | 7 8 2
// ---------------------
// 1 4 6 | 7 2 9 | 3 5 8
// 5 2 9 | 1 8 3 | 6 4 7
// 7 8 3 | 4 6 5 | 2 1 9
```