aoc2023/day-10/two.go
onyx-and-iris 7cf383d9c9 move steps into tracker... it is afterall, the tracker
initializeTracker should be a factory function
2023-12-11 12:08:55 +00:00

41 lines
692 B
Go

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
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
}