Skip to content

Commit 124c175

Browse files
committed
chore: start of day 9 part 2
1 parent b390a4b commit 124c175

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

go/2025/puzzles/day09/main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"math"
6+
"slices"
67
"strings"
78

89
"github.com/believer/aoc-utils/files"
@@ -49,6 +50,11 @@ func part1(name string) (largestArea int) {
4950
return
5051
}
5152

53+
type Rectangle struct {
54+
P1, P2 grid.Point
55+
Area int
56+
}
57+
5258
func part2(name string) (largestArea int) {
5359
lines := files.ReadLines(name)
5460
coords := []grid.Point{}
@@ -62,5 +68,37 @@ func part2(name string) (largestArea int) {
6268
})
6369
}
6470

71+
rectangles := []Rectangle{}
72+
73+
for i := range len(coords) {
74+
p1 := coords[i]
75+
76+
for j := i + 1; j < len(coords); j++ {
77+
p2 := coords[j]
78+
79+
// Add one to include the red corner tiles
80+
dx := math.Abs(float64(p2.X)-float64(p1.X)) + 1
81+
dy := math.Abs(float64(p2.Y)-float64(p1.Y)) + 1
82+
83+
area := int(dx * dy)
84+
rectangles = append(rectangles, Rectangle{P1: p1, P2: p2, Area: area})
85+
}
86+
}
87+
88+
slices.SortFunc(rectangles, func(a, b Rectangle) int {
89+
return b.Area - a.Area
90+
})
91+
92+
for _, r := range rectangles {
93+
minX := math.Max(float64(r.P1.X), float64(r.P2.X))
94+
maxX := math.Min(float64(r.P1.X), float64(r.P2.X))
95+
minY := math.Min(float64(r.P1.Y), float64(r.P2.Y))
96+
maxY := math.Max(float64(r.P1.Y), float64(r.P2.Y))
97+
98+
fmt.Println(minX, maxX, minY, maxY)
99+
}
100+
101+
fmt.Println(rectangles)
102+
65103
return
66104
}

0 commit comments

Comments
 (0)