-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (41 loc) · 743 Bytes
/
main.go
File metadata and controls
53 lines (41 loc) · 743 Bytes
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
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
)
func solve(r io.Reader) {
raw, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
rows := strings.Split(string(raw), "\r\n")
valid := 0
curr := make(map[string]bool)
for _, row := range rows {
if len(row) == 0 {
_, hasCid := curr["cid"]
if len(curr) == 8 || (len(curr) == 7 && !hasCid) {
valid += 1
}
curr = make(map[string]bool)
continue
}
items := strings.Split(row, " ")
for _, item := range items {
parts := strings.Split(item, ":")
curr[parts[0]] = true
}
}
fmt.Println(valid)
}
func main() {
input, err := os.Open(path.Join("2020", "4", "input.txt"))
if err != nil {
panic(err)
}
solve(input)
}