aoc2024/day-04/internal/one/neighbours.go

59 lines
1.1 KiB
Go
Raw Normal View History

2024-12-05 01:31:44 +00:00
package one
type neighbour struct {
x int
y int
direction int
}
func newNeighbour(direction, x, y int) neighbour {
switch direction {
case N:
return neighbour{x, y + 1, direction}
case NE:
return neighbour{x + 1, y + 1, direction}
case E:
return neighbour{x + 1, y, direction}
case SE:
return neighbour{x + 1, y - 1, direction}
case S:
return neighbour{x, y - 1, direction}
case SW:
return neighbour{x - 1, y - 1, direction}
case W:
return neighbour{x - 1, y, direction}
case NW:
return neighbour{x - 1, y + 1, direction}
default:
return neighbour{}
}
}
type neighbours struct {
N neighbour
NE neighbour
E neighbour
SE neighbour
S neighbour
SW neighbour
W neighbour
NW neighbour
}
func newNeighbours(x, y int) neighbours {
return neighbours{
newNeighbour(N, x, y),
newNeighbour(NE, x, y),
newNeighbour(E, x, y),
newNeighbour(SE, x, y),
newNeighbour(S, x, y),
newNeighbour(SW, x, y),
newNeighbour(W, x, y),
newNeighbour(NW, x, y),
}
}
func (n neighbours) all() [8]neighbour {
return [8]neighbour{n.N, n.NE, n.E, n.SE, n.S, n.SW, n.W, n.NW}
}