mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 23:20:49 +00:00
51 lines
935 B
Go
51 lines
935 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"os"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
// readlines reads lines from stdin.
|
||
|
// returns input 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
|
||
|
}
|
||
|
|
||
|
// inLastMoves checks if next coords exists in past moves
|
||
|
func inLastMoves(last []coords, b coords) bool {
|
||
|
for _, co := range last {
|
||
|
if co.X == b.X && co.Y == b.Y {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// comparePoints returns true if coordinates for two points match
|
||
|
func comparePoints(a, b point) bool {
|
||
|
return a.X == b.X && a.Y == b.Y
|
||
|
}
|
||
|
|
||
|
// contains returns true if a slice of elements contains a given element
|
||
|
func contains[T comparable](elems []T, v T) bool {
|
||
|
for _, s := range elems {
|
||
|
if v == s {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|