refactor: add positions method to grid and use that for iterating in day 4 part 1

This commit is contained in:
Stevan Freeborn
2025-12-07 21:33:11 -06:00
parent 5dfbd2d9b3
commit 5586641aff
3 changed files with 69 additions and 19 deletions
+12
View File
@@ -13,6 +13,7 @@ type Grid interface {
InBounds(position.Position) bool
GetValueAt(position.Position) string
GetSameNeighborsOf(position.Position, []move.Move) []position.Position
Positions() map[position.Position]string
}
type grid struct {
@@ -95,3 +96,14 @@ func (g grid) GetSameNeighborsOf(pos position.Position, moves []move.Move) []pos
return similarNeighbors
}
func (g grid) Positions() map[position.Position]string {
positions := map[position.Position]string{}
for pos, value := range g.positions {
newPosition := position.From(pos.Row(), pos.Column())
positions[newPosition] = value
}
return positions
}