Skip to content

Commit

Permalink
add techniques.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nervonment committed May 29, 2024
1 parent 72bb8b9 commit ff43a60
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions techniques.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## 基本定义

`board: [[i8; 9]; 9]` 棋盘。
`row_contains: [[bool; 10]; 9]` 各行的填充情况,`row_contains[r][num]``true` 代表第 `r` 行填有数字 `num`
`col_contains: [[bool; 10]; 9]` 各列的填充情况,同上
`blk_contains: [[bool; 10]; 9]` 各宫的填充情况,同上
`candidate: [[([bool; 10], i8); 9]; 9]` 各格的候选数字。`candidate[r][c]` 是格 `(r, c)` 的候选数字列表(即 `remind`),其中 `.0[num]` 代表 `num` 是否位于此格的候选数字列表中,`.1` 代表此格的候选数字列表中有多少个数字。题目创建伊始,可以通过每格所在的行列宫筛选出该格的候选数字列表;解题过程中可使用技巧进行更新。

## 技巧

以下两个技巧可以直接确定某一格应填的数字:

- **hidden single**
定义:某一行/列/宫的所有格的候选数字列表中,只有某一格有 num
操作:可以确定这一格填 num

- **naked single**
定义:某一格只剩一个候选数字
操作:可以确定这一格填 num

剩下的技巧可以更新某些格的候选数字列表,从而间接地应用 **hidden single****naked single** 而确定某一格应填的数字。

- **hidden pair**
定义:某一行/列/宫的所有格的候选数字列表中,只有某两格有 num1 和 num2
操作:可以从这从这两格的候选数字列表中移除其他数字

- **naked pair**
定义:某一行/列/宫的某两格的候选数字列表中只有 num1 和 num2
操作:可以从这一行/列/宫的其他格的候选数字列表中移除 num1 和 num2

- 类似可定义 hidden tuple, naked tuple

- **pointing**
定义:某一宫的所有*候选数字列表包含 num 的格*均在同一行/列
操作:可以从这一行/列中不在这一宫内的格的候选数字列表中移除 num

- **claiming**
定义:某一行/列的所有*候选数字列表包含 num 的格*均在同一宫
操作:可以从这一宫中不在这一行/列内的格的候选数字列表中移除 num

0 comments on commit ff43a60

Please sign in to comment.