2019 Day 15 Complete

This commit is contained in:
2019-12-18 16:44:05 -06:00
parent 14fcb13c3c
commit 068b018cc0
3 changed files with 118 additions and 86 deletions

View File

@@ -29,8 +29,6 @@ type Maze struct {
dirHistory []int
dnt bool
bfs map[*helpers.Coordinate]*BFSNode
startCoord *helpers.Coordinate
o2Coord *helpers.Coordinate
}
@@ -43,7 +41,6 @@ func NewMaze() *Maze {
maxY: helpers.MIN_INT,
minY: helpers.MAX_INT,
bot: helpers.NewCoordinate(0, 0),
bfs: make(map[*helpers.Coordinate]*BFSNode),
startCoord: helpers.NewCoordinate(0, 0),
}
m.path = append(m.path, helpers.NewCoordinate(0, 0))
@@ -51,29 +48,6 @@ func NewMaze() *Maze {
}
func (m *Maze) SetCoord(c *helpers.Coordinate, val int) {
var b *BFSNode
var ok bool
if b, ok = m.bfs[c]; !ok {
b = &BFSNode{Value: val}
m.bfs[c] = b
}
// Create the BFS node for this
if n, ok := m.bfs[c.GetNorthCoord()]; ok {
n.South = b
b.North = n
}
if e, ok := m.bfs[c.GetEastCoord()]; ok {
e.West = b
b.East = e
}
if s, ok := m.bfs[c.GetSouthCoord()]; ok {
s.North = b
b.South = s
}
if w, ok := m.bfs[c.GetWestCoord()]; ok {
w.East = b
b.West = w
}
if val == 2 {
m.o2Coord = c
}
@@ -170,26 +144,3 @@ func (m *Maze) Print() {
fmt.Println()
}
}
type BFSNode struct {
Value int
North, East *BFSNode
South, West *BFSNode
}
func (b *BFSNode) getChildren() []*BFSNode {
var ret []*BFSNode
if b.North != nil {
ret = append(ret, b.North)
}
if b.East != nil {
ret = append(ret, b.East)
}
if b.South != nil {
ret = append(ret, b.South)
}
if b.West != nil {
ret = append(ret, b.West)
}
return ret
}