-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare.go
60 lines (51 loc) · 1.02 KB
/
square.go
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
package main
/*****
* A square has a list of possible numbers, and pointers to the
* row, collumn, and cluster it is located in.
*****/
type square struct {
pos int
final int
numbers map[int]bool
row *collection
collumn *collection
cluster *collection
}
/*****
* Allocate and initialise a square.
*****/
func NewSquare(pos, val int) (*square) {
s := &square{pos, 0, make(map[int]bool), nil, nil, nil}
if val == 0 {
for i := 1; i < 10; i++ {
s.numbers[i] = true
}
} else {
s.final = val
}
return s
}
/*****
* Update the possible numbers for the square.
*****/
func (square *square) Remove(x int) bool {
if square.final != 0 {
return false
}
delete(square.numbers, x)
if len(square.numbers) == 1 {
for key, _ := range square.numbers {
square.final = key
return true
}
}
return false
}
/*****
* Call all relevant UpdateUsed methods.
*****/
func (self *square) UpdateUsed() {
self.row.UpdateUsed()
self.collumn.UpdateUsed()
self.cluster.UpdateUsed()
}