feat: solve day nine part 1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
|
||||
)
|
||||
|
||||
func SolvePartOne(filePath string) int {
|
||||
points := []struct {
|
||||
x int
|
||||
y int
|
||||
}{}
|
||||
|
||||
for line := range file.ReadLines(filePath) {
|
||||
parts := strings.Split(line, ",")
|
||||
x, _ := strconv.Atoi(parts[0])
|
||||
y, _ := strconv.Atoi(parts[1])
|
||||
p := struct {
|
||||
x int
|
||||
y int
|
||||
}{x: x, y: y}
|
||||
points = append(points, p)
|
||||
}
|
||||
|
||||
numberOfPoints := len(points)
|
||||
largestArea := 0
|
||||
|
||||
for i := range numberOfPoints {
|
||||
for j := i + 1; j < numberOfPoints; j++ {
|
||||
start := points[i]
|
||||
end := points[j]
|
||||
|
||||
width := int(math.Abs(float64(end.x-start.x)) + 1)
|
||||
height := int(math.Abs(float64(end.y-start.y)) + 1)
|
||||
|
||||
a := width * height
|
||||
|
||||
if a > largestArea {
|
||||
largestArea = a
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return largestArea
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/09"
|
||||
)
|
||||
|
||||
func TestSolvePartOneWithExampleInput(t *testing.T) {
|
||||
expected := 50
|
||||
|
||||
result := solution.SolvePartOne("EXAMPLE.txt")
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("got %d but wanted %d", result, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSolvePartOneWithInput(t *testing.T) {
|
||||
expected := 4_758_121_828
|
||||
|
||||
result := solution.SolvePartOne("INPUT.txt")
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("got %d but wanted %d", result, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user