mirror of
				https://github.com/onyx-and-iris/aoc2023.git
				synced 2025-11-04 06:41:45 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			692 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			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
 | 
						|
}
 |