mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
54 lines
882 B
Go
54 lines
882 B
Go
|
package main
|
||
|
|
||
|
/*
|
||
|
functions that check connections between pipes in each direction
|
||
|
*/
|
||
|
|
||
|
func checkSouth(point point) point {
|
||
|
if point.Y == len(pointsArray)-1 {
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
target := pointsArray[point.Y+1].points[point.X]
|
||
|
if point.S && target.N {
|
||
|
return target
|
||
|
}
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
func checkEast(point point) point {
|
||
|
if point.X == len(pointsArray[point.Y].points)-1 {
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
target := pointsArray[point.Y].points[point.X+1]
|
||
|
if point.E && target.W {
|
||
|
return target
|
||
|
}
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
func checkNorth(point point) point {
|
||
|
if point.Y == 0 {
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
target := pointsArray[point.Y-1].points[point.X]
|
||
|
if point.N && target.S {
|
||
|
return target
|
||
|
}
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
func checkWest(point point) point {
|
||
|
if point.X == 0 {
|
||
|
return point
|
||
|
}
|
||
|
|
||
|
target := pointsArray[point.Y].points[point.X-1]
|
||
|
if point.W && target.E {
|
||
|
return target
|
||
|
}
|
||
|
return point
|
||
|
}
|