day 09 - part 1

This commit is contained in:
Simon Ziegler
2025-12-10 16:29:34 +01:00
parent 80ae5ea954
commit a05cb9d41f
3 changed files with 554 additions and 0 deletions

50
09/main.go Normal file
View File

@@ -0,0 +1,50 @@
package main
import (
"fmt"
"math"
"strings"
"git.z1glr.de/advent-of-code-2025/pkg/aoc"
)
type Point struct {
X, Y int
}
func (p Point) Area(p2 Point) float64 {
return math.Abs(float64((p.X - p2.X + 1) * (p.Y - p2.Y + 1)))
}
func do(test bool) (int, int) {
rows := aoc.ReadFileRows(test)
points := make([]Point, len(rows))
for ii, rr := range rows {
parts := strings.Split(rr, ",")
points[ii] = Point{
X: aoc.ParseInt(parts[0]),
Y: aoc.ParseInt(parts[1]),
}
}
largestArea := 0.0
for ii, p1 := range points {
for _, p2 := range points[ii+1:] {
largestArea = math.Max(largestArea, p1.Area(p2))
}
}
fmt.Printf("%9.0f\n", largestArea)
return int(largestArea), 0
}
func main() {
if r1, r2 := do(true); r1 == 50 && r2 == 0 {
do(false)
}
}