-
Notifications
You must be signed in to change notification settings - Fork 2
/
mask.go
49 lines (43 loc) · 844 Bytes
/
mask.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
package sudoku
import "bytes"
type Mask [GridSize]bool
func (m *Mask) String() string {
var buf bytes.Buffer
for i := 0; i < GridSize; i++ {
if m[i] {
buf.WriteString("✓")
} else {
buf.WriteString("✗")
}
if i % Size == Size-1 {
buf.WriteByte('\n')
} else {
buf.WriteByte(' ')
}
}
return buf.String()
}
// Equal returns whether two masks contain the same values.
func (a *Mask) Equal(b Mask) bool {
for i := 0; i < GridSize; i++ {
if a[i] != b[i] {
return false
}
}
return true
}
// Fill sets all values of the Mask to 'v'.
func (m *Mask) Fill(v bool) {
for i := 0; i < GridSize; i++ {
m[i] = v
}
}
// Count returns the number of cells in the Mask having the given value.
func (m *Mask) Count(v bool) (count int) {
for i := 0; i < GridSize; i++ {
if m[i] == v {
count++
}
}
return
}