day23: started hardcode of part2, way too slow

This commit is contained in:
efim
2023-12-23 10:19:25 +00:00
parent 44de1377ca
commit 7ebb6dee2c
4 changed files with 101 additions and 2 deletions

View File

@@ -27,6 +27,35 @@ type Field struct {
StartCol, EndCol int
}
func (f *Field) NeighborsPart2(c Coord) (neighbors []Coord) {
symb, exists := f.Cells[c]
if !exists {
panic(fmt.Sprintf("coord %+v not found in field", c))
}
var coords []Coord
switch symb {
case Tree:
panic(fmt.Sprintf("attempting to get neighbors of a tree at %+v", c))
default:
coords = []Coord{
{Row: c.Row + 1, Col: c.Col},
{Row: c.Row - 1, Col: c.Col},
{Row: c.Row, Col: c.Col + 1},
{Row: c.Row, Col: c.Col - 1},
}
}
for _, coord := range coords {
neighborSymb, found := f.Cells[coord]
if !found || neighborSymb == Tree {
continue
}
neighbors = append(neighbors, coord)
}
return
}
func (f *Field) Neighbors(c Coord) (neighbors []Coord) {
symb, exists := f.Cells[c]
if !exists {