Compare commits

..

2 Commits

Author SHA1 Message Date
2d6c89d7c9 feat: add solution for p1 2025-11-28 16:45:04 +01:00
6bc4c1b5a5 test: add unit test for p1 2025-11-28 16:44:58 +01:00
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package daytwo
import (
"advent-of-code/internal/registry"
"os"
"strconv"
"strings"
)
func init() {
registry.Register("2015D2", ParseInput, PartOne, PartTwo)
}
func ParseInput(filepath string) []string {
content, _ := os.ReadFile(filepath)
return strings.Split(string(content), "\n")
}
func PartOne(data []string) int {
total := 0
for _, line := range data {
parts := strings.Split(line, "x")
length, _ := strconv.Atoi(parts[0])
width, _ := strconv.Atoi(parts[1])
height, _ := strconv.Atoi(parts[2])
total += 2*length*width + 2*width*height + 2*height*length + min(length*width, width*height, height*length)
}
return total
}
func PartTwo(data []string) int {
return 0
}

View File

@@ -0,0 +1,23 @@
package daytwo
import "testing"
func TestPartOne(t *testing.T) {
tests := []struct {
name string
input string
expected int
}{
{"2x3x4", "2x3x4", 58},
{"1x1x10", "1x1x10", 43},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := PartOne([]string{tt.input})
if got != tt.expected {
t.Errorf("PartOne(%q) = %d, want %d", tt.input, got, tt.expected)
}
})
}
}