feat: solve day 8 part 1...twice

This commit is contained in:
Stevan Freeborn
2025-12-16 13:20:29 -06:00
parent f6d1aed872
commit 1bfa196f21
11 changed files with 652 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
// Package connection provides a model and methods for connections between junction boxes.
package connection
import "github.com/StevanFreeborn/advent-of-code-2025/cmd/08/box"
type Connection interface {
Start() box.Box
End() box.Box
Distance() float64
}
type connection struct {
start box.Box
end box.Box
distance float64
}
func (c connection) Start() box.Box {
return c.start
}
func (c connection) End() box.Box {
return c.end
}
func (c connection) Distance() float64 {
return c.distance
}
func From(start box.Box, end box.Box) Connection {
return connection{
start: start,
end: end,
distance: start.DistanceFrom(end),
}
}
+28
View File
@@ -0,0 +1,28 @@
package connection_test
import (
"testing"
"github.com/StevanFreeborn/advent-of-code-2025/cmd/08/box"
"github.com/StevanFreeborn/advent-of-code-2025/cmd/08/connection"
)
func TestFrom(t *testing.T) {
start := box.From("1,2,3")
end := box.From("4,5,6")
expectedDistance := start.DistanceFrom(end)
conn := connection.From(start, end)
if conn.Start() != start {
t.Errorf("Connection Start() = %v; want %v", conn.Start(), start)
}
if conn.End() != end {
t.Errorf("Connection End() = %v; want %v", conn.End(), end)
}
if conn.Distance() != expectedDistance {
t.Errorf("Connection Distance() = %v; want %v", conn.Distance(), expectedDistance)
}
}