-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
67 lines (61 loc) · 1.4 KB
/
interface.go
File metadata and controls
67 lines (61 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package law
type changeNode struct {
change_type int
pre *changeNode
list *[]int
}
func CheckList(list []int) (int, bool) {
return checkList(list)
}
func checkList(list []int) (val int, ok bool) {
val, ok = 0, false
root := BuildCheckChain()
changers := []changer{getDiffList, getDivList, getOpenRoot}
var bfs func(list []int) (bool, int, changeNode)
bfs = func(list []int) (bool, int, changeNode) {
queue := []changeNode{{list: &list}}
for len(queue) > 0 {
newChange := queue[0]
ok_, v := check(root, *newChange.list)
if ok_ {
return ok_, v, newChange
}
for inx, changer := range changers {
if len(*newChange.list) < 4 {
continue
}
new_list := changer(*newChange.list)
if new_list == nil {
continue
}
change := changeNode{list: &new_list, change_type: inx + 1, pre: &newChange}
queue = append(queue, change)
}
queue = queue[1:]
}
return false, 0, changeNode{}
}
ok, val, change := bfs(list)
if !ok {
return
}
ok, val = inverseOperation(&change, val)
return
}
func BuildCheckChain() *checkNode {
// 构建检查责任链
nodes := []checker{checkEquivocation, checkIsometric, checkOpenRootEquivocation}
return linkCheck(nodes...)
}
func invOperationFactor(c int) (inv invChanger) {
// 逆操作的简单工厂
switch c {
case 1:
inv = invDiff
case 2:
inv = invMultiplication
case 3:
inv = invOpenRoot
}
return
}