Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
数独生成 & 计算 算法
- Host: GitHub
- URL: https://github.com/0x-jerry/sudoku
- Owner: 0x-jerry
- License: mit
- Created: 2019-08-29T07:42:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:47:22.000Z (about 1 year ago)
- Last Synced: 2024-04-17T19:24:56.180Z (9 months ago)
- Topics: sudoku, sudoku-generator, sudoku-solver
- Language: JavaScript
- Homepage: https://0x-jerry.github.io/sudoku/
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```