mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
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}
|
|
}
|