From e84468eb4813c846b6800975b03611f9cf812008 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Wed, 17 Dec 2025 05:50:56 -0600 Subject: [PATCH] feat: solve day nine part 1 --- README.md | 2 +- cmd/09/main.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ cmd/09/main_test.go | 27 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 cmd/09/main.go create mode 100644 cmd/09/main_test.go diff --git a/README.md b/README.md index 7f69706..ac3a21e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ go test ./cmd/01 | 06 | [Problem](https://adventofcode.com/2025/day/6) | [Solution](./cmd/06/) | Part 1 I don't think it is the best solution, but it does solve it. I kicked ass on part 2. 🥳 | | 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | FIFO for life. 🤣. Fuck me...part 2 I found really difficult and the use of DFS was obvious, but doing the memoizing was not. | | 08 | [Problem](https://adventofcode.com/2025/day/8) | [Solution](./cmd/08/) | Part 1 had me down bad. I was on the right track with my original solution, but ended up doing it in a brute force way then figuring out my mistake with the original. Fuck this guy. Part 2 was so much easier once part 1 was sorted out. | -| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | | +| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | Part 1 was such a nice break from the madness of day 8. | | 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | | | 11 | [Problem](https://adventofcode.com/2025/day/11) | [Solution](./cmd/11/) | | | 12 | [Problem](https://adventofcode.com/2025/day/12) | [Solution](./cmd/12/) | | diff --git a/cmd/09/main.go b/cmd/09/main.go new file mode 100644 index 0000000..4cdda16 --- /dev/null +++ b/cmd/09/main.go @@ -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 +} diff --git a/cmd/09/main_test.go b/cmd/09/main_test.go new file mode 100644 index 0000000..405ac26 --- /dev/null +++ b/cmd/09/main_test.go @@ -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) + } +}