aoc2023/day-16/util.go

46 lines
853 B
Go
Raw Permalink Normal View History

2023-12-17 15:31:11 +00:00
package main
import (
"bufio"
"log"
"os"
)
// readlines reads lines from stdin.
// it returns them as an array of strings
func readlines() []string {
lines := []string{}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return lines
}
// nodeInNodes returns true if node n is in nodes
// X, Y coords and direction must match
func nodeInNodes(n node, nodes []node) bool {
for _, node := range nodes {
if n.X == node.X && n.Y == node.Y && n.direction == node.direction {
return true
}
}
return false
}
// coordInCoords returns true if coords c is in coords
func coordInCoords(c coords, coords []coords) bool {
for _, coord := range coords {
if c.X == coord.X && c.Y == coord.Y {
return true
}
}
return false
}