@@ -2,7 +2,6 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
- "strconv"
6
5
)
7
6
8
7
// SolveDay6 solves the puzzle for day6
@@ -47,18 +46,31 @@ func solveDay6Part1(lines *[]string) {
47
46
func solveDay6Part2 (lines * []string ) {
48
47
solution := 0
49
48
50
- for i , lineI := range * lines {
51
- valueI , _ := strconv .Atoi (lineI )
52
- for j , lineJ := range (* lines )[i + 1 :] {
53
- valueJ , _ := strconv .Atoi (lineJ )
54
- for _ , lineK := range (* lines )[j + 1 :] {
55
- valueK , _ := strconv .Atoi (lineK )
56
- if valueI + valueJ + valueK == 2020 {
57
- solution = valueI * valueJ * valueK
58
- break
49
+ groupAnswersMap := map [string ]int {}
50
+ personCount := 0
51
+ * lines = append (* lines , "" ) // append an empty line as the differentiator between groups
52
+ for _ , personAnswers := range * lines {
53
+
54
+ if personAnswers != "" {
55
+ personCount ++
56
+ for i := 0 ; i < len (personAnswers ); i ++ {
57
+ singleAnswer := personAnswers [i ]
58
+ groupAnswersMap [string (singleAnswer )] = groupAnswersMap [string (singleAnswer )] + 1
59
+ }
60
+ fmt .Println (groupAnswersMap )
61
+ } else {
62
+ fmt .Println ("eog" )
63
+ for _ , v := range groupAnswersMap {
64
+ if v == personCount {
65
+ solution ++
59
66
}
60
67
}
68
+
69
+ groupAnswersMap = map [string ]int {}
70
+ personCount = 0
61
71
}
62
72
}
73
+
63
74
fmt .Println (solution )
75
+
64
76
}
0 commit comments