aoc2024/day-16/internal/one/neighbours.go
2024-12-17 01:58:33 +00:00

33 lines
551 B
Go

package one
func neighbours(p node) [3]node {
switch p.direction {
case N:
return [3]node{
newNode(p.x, p.y-1, N),
newNode(p.x-1, p.y, W),
newNode(p.x+1, p.y, E),
}
case E:
return [3]node{
newNode(p.x+1, p.y, E),
newNode(p.x, p.y-1, N),
newNode(p.x, p.y+1, S),
}
case S:
return [3]node{
newNode(p.x, p.y+1, S),
newNode(p.x-1, p.y, W),
newNode(p.x+1, p.y, E),
}
case W:
return [3]node{
newNode(p.x-1, p.y, W),
newNode(p.x, p.y+1, S),
newNode(p.x, p.y-1, N),
}
default:
return [3]node{}
}
}