aoc2023/day-10/two.go

41 lines
692 B
Go
Raw Permalink Normal View History

2023-12-11 03:55:09 +00:00
package main
import (
"fmt"
"math"
log "github.com/sirupsen/logrus"
)
func debugPrint() {
for _, points := range pointsArray {
for _, point := range points.points {
if contains(loop, point.coords) {
fmt.Printf("%c ", point.identifier)
} else {
fmt.Printf(". ")
}
}
fmt.Printf("\n")
}
}
var loop []coords
// two returns the number of coords that sit inside the polygon
2023-12-11 03:55:09 +00:00
func two(lines []string) int {
if log.GetLevel() == log.DebugLevel {
debugPrint()
}
area := 0
for i := 0; i < len(loop); i++ {
next := loop[(i+1)%len(loop)]
area += loop[i].X*next.Y - loop[i].Y*next.X
}
area = int(math.Abs(float64(area))) / 2
return area - len(loop)/2 + 1
}