From 314da544957dcf80c1cade5cfb5e3785f32e3add Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 25 Nov 2025 23:12:50 +0100 Subject: [PATCH] feat: complete part two --- 2020/day06/main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/2020/day06/main.go b/2020/day06/main.go index 5591124..ad71c8c 100644 --- a/2020/day06/main.go +++ b/2020/day06/main.go @@ -39,7 +39,37 @@ func PartOne(input []string) int { return total } +func PartTwo(input []string) int { + total := 0 + groupAnswers := make(map[rune]int) + groupSize := 0 + + for idx, line := range input { + if line != "" { + groupSize++ + for _, char := range line { + if char >= 'a' && char <= 'z' { + groupAnswers[char]++ + } + } + } + + if line == "" || idx == len(input)-1 { + for _, count := range groupAnswers { + if count == groupSize { + total++ + } + } + groupAnswers = make(map[rune]int) + groupSize = 0 + } + } + + return total +} + func main() { input := parseInput("input.txt") fmt.Println("Part 1:", PartOne(input)) + fmt.Println("Part 2:", PartTwo(input)) }