refactor: massive refactor to have only one binary to call

This commit is contained in:
2025-11-26 14:03:32 +01:00
parent 314da54495
commit 3723f84d1a
41 changed files with 272 additions and 188 deletions

View File

@@ -0,0 +1,43 @@
package dayone
import (
"advent-of-code/internal/registry"
"os"
"strconv"
"strings"
)
func init() {
registry.Register("2021D1", ParseInput, PartOne, PartTwo)
}
func ParseInput(filepath string) []int {
content, _ := os.ReadFile(filepath)
var data []int
for line := range strings.SplitSeq(string(content), "\n") {
num, _ := strconv.Atoi(line)
data = append(data, num)
}
return data
}
func PartOne(data []int) int {
count := 0
for i := 1; i < len(data); i++ {
if data[i] > data[i-1] {
count++
}
}
return count
}
func PartTwo(data []int) int {
count := 0
for i := 3; i < len(data); i++ {
if data[i] > data[i-3] {
count++
}
}
return count
}

View File

@@ -0,0 +1,22 @@
package dayone
import "testing"
var testInput = []int{199, 200, 208, 210, 200, 207, 240, 269, 260, 263}
func TestPartOne(t *testing.T) {
expected := 7
got := PartOne(testInput)
if got != expected {
t.Errorf("PartOne() = %d, want %d", got, expected)
}
}
func TestPartTwo(t *testing.T) {
expected := 5
got := PartTwo(testInput)
if got != expected {
t.Errorf("PartTwo() = %d, want %d", got, expected)
}
}