mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
move enqueue(ns[dir]) into loop
This commit is contained in:
parent
33ee076cf1
commit
5a6947af2c
@ -47,36 +47,30 @@ func exploreBFS(graph *graph, dir direction) (*orderedmap.OrderedMap[point, stru
|
|||||||
case '#':
|
case '#':
|
||||||
return om, false
|
return om, false
|
||||||
case '[', ']':
|
case '[', ']':
|
||||||
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir])))
|
nextDirections := []direction{dir}
|
||||||
queue.Enqueue(ns[dir])
|
|
||||||
_, ok := om.Get(ns[dir])
|
|
||||||
if !ok {
|
|
||||||
om.Set(ns[dir], struct{}{})
|
|
||||||
}
|
|
||||||
|
|
||||||
var additionalDirections []direction
|
|
||||||
if graph.valueAt(ns[dir]) == '[' {
|
if graph.valueAt(ns[dir]) == '[' {
|
||||||
switch dir {
|
switch dir {
|
||||||
case N:
|
case N:
|
||||||
additionalDirections = []direction{NE}
|
nextDirections = append(nextDirections, NE)
|
||||||
case S:
|
case S:
|
||||||
additionalDirections = []direction{SE}
|
nextDirections = append(nextDirections, SE)
|
||||||
}
|
}
|
||||||
} else if graph.valueAt(ns[dir]) == ']' {
|
} else if graph.valueAt(ns[dir]) == ']' {
|
||||||
switch dir {
|
switch dir {
|
||||||
case N:
|
case N:
|
||||||
additionalDirections = []direction{NW}
|
nextDirections = append(nextDirections, NW)
|
||||||
case S:
|
case S:
|
||||||
additionalDirections = []direction{SW}
|
nextDirections = append(nextDirections, SW)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dir := range additionalDirections {
|
for _, nextDirection := range nextDirections {
|
||||||
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir])))
|
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[nextDirection])))
|
||||||
queue.Enqueue(ns[dir])
|
queue.Enqueue(ns[nextDirection])
|
||||||
_, ok := om.Get(ns[dir])
|
_, ok := om.Get(ns[nextDirection])
|
||||||
if !ok {
|
if !ok {
|
||||||
om.Set(ns[dir], struct{}{})
|
om.Set(ns[nextDirection], struct{}{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user