51 lines
784 B
Go
51 lines
784 B
Go
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)
|
|
}
|
|
}
|