-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.go
60 lines (52 loc) · 1.19 KB
/
6.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
import (
"fmt"
"strings"
)
func main6() {
input := getDeclarationForms()
newGroup := false
var groups []string
group := ""
// easier to parse group array
for i, row := range input {
if len(row) == 0 {
newGroup = true
} else {
group += row + "\n"
}
if newGroup == true || i == len(input)-1 {
groups = append(groups, group)
group = ""
newGroup = false
}
}
answeredByAnyone := 0
for _, group := range groups {
answered := make(map[string]struct{})
for _, char := range group {
if string(char) == "\n" {
continue
}
answered[string(char)] = struct{}{}
}
answeredByAnyone += len(answered)
}
fmt.Println("part 1:", answeredByAnyone, "questions anyone answered") // 6778
answeredByEveryone := 0
for _, group := range groups {
var answered []interface{}
persons := strings.Split(group, "\n")
for pid, person := range persons {
if pid == 0 {
for _, answer := range person {
answered = append(answered, answer)
}
} else if len(person) != 0 {
answered = intersect(answered, []rune(person))
}
}
answeredByEveryone += len(answered)
}
fmt.Println("part 2:", answeredByEveryone, "questions everybody answered")
}