Compare commits

...

2 Commits

Author SHA1 Message Date
314da54495 feat: complete part two 2025-11-25 23:12:50 +01:00
3ab410ea06 test: add unit test for part two 2025-11-25 23:12:42 +01:00
2 changed files with 38 additions and 0 deletions

View File

@@ -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))
}

View File

@@ -27,3 +27,11 @@ func TestPartOne(t *testing.T) {
t.Errorf("PartOne() = %d, want %d", got, expected)
}
}
func TestPartTwo(t *testing.T) {
expected := 6
got := PartTwo(input)
if got != expected {
t.Errorf("PartTwo() = %d, want %d", got, expected)
}
}