Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b70c6a

Browse files
day 6
1 parent 107731d commit 2b70c6a

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

‎bin/adventofcode2020

0 Bytes
Binary file not shown.

‎src/day6.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"strconv"
65
)
76

87
// SolveDay6 solves the puzzle for day6
@@ -47,18 +46,31 @@ func solveDay6Part1(lines *[]string) {
4746
func solveDay6Part2(lines *[]string) {
4847
solution := 0
4948

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++
5966
}
6067
}
68+
69+
groupAnswersMap = map[string]int{}
70+
personCount = 0
6171
}
6272
}
73+
6374
fmt.Println(solution)
75+
6476
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /