refactor: add positions method to grid and use that for iterating in day 4 part 1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user