Compare commits

...

4 Commits

Author SHA1 Message Date
497314aa8b test: add unit test for part one 2025-11-25 22:44:46 +01:00
ce1cc9d5cf feat: complete part one 2025-11-25 22:44:37 +01:00
b2f1a2902c feat: add input 2025-11-25 22:44:30 +01:00
de59203640 go: init 2020/day06 package 2025-11-25 22:44:25 +01:00
4 changed files with 2224 additions and 0 deletions

3
2020/day06/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module 2020/day06
go 1.25.4

2147
2020/day06/input.txt Normal file

File diff suppressed because it is too large Load Diff

45
2020/day06/main.go Normal file
View File

@@ -0,0 +1,45 @@
package main
import (
"fmt"
"log"
"os"
"strings"
)
func parseInput(file string) []string {
content, err := os.ReadFile(file)
if err != nil {
log.Fatalf("Failed to read input file: %v", err)
}
return strings.Split(strings.TrimSpace(string(content)), "\n")
}
func PartOne(input []string) int {
total := 0
groupAnswers := make(map[rune]bool)
for i, line := range input {
if line != "" {
for _, char := range line {
if char >= 'a' && char <= 'z' {
groupAnswers[char] = true
}
}
}
if line == "" || i == len(input)-1 {
total += len(groupAnswers)
groupAnswers = make(map[rune]bool)
}
}
total += len(groupAnswers)
return total
}
func main() {
input := parseInput("input.txt")
fmt.Println("Part 1:", PartOne(input))
}

29
2020/day06/main_test.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import "testing"
var input = []string{
"abc",
"",
"a",
"b",
"c",
"",
"ab",
"ac",
"",
"a",
"a",
"a",
"a",
"",
"b",
}
func TestPartOne(t *testing.T) {
expected := 11
got := PartOne(input)
if got != expected {
t.Errorf("PartOne() = %d, want %d", got, expected)
}
}