From 5a6947af2ce94befb98892c8a0baa7227f068e05 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 25 Dec 2024 21:01:35 +0000 Subject: [PATCH] move enqueue(ns[dir]) into loop --- day-15/internal/two/explore.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/day-15/internal/two/explore.go b/day-15/internal/two/explore.go index cf4c32e..83d21e5 100644 --- a/day-15/internal/two/explore.go +++ b/day-15/internal/two/explore.go @@ -47,36 +47,30 @@ func exploreBFS(graph *graph, dir direction) (*orderedmap.OrderedMap[point, stru case '#': return om, false case '[', ']': - log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir]))) - queue.Enqueue(ns[dir]) - _, ok := om.Get(ns[dir]) - if !ok { - om.Set(ns[dir], struct{}{}) - } + nextDirections := []direction{dir} - var additionalDirections []direction if graph.valueAt(ns[dir]) == '[' { switch dir { case N: - additionalDirections = []direction{NE} + nextDirections = append(nextDirections, NE) case S: - additionalDirections = []direction{SE} + nextDirections = append(nextDirections, SE) } } else if graph.valueAt(ns[dir]) == ']' { switch dir { case N: - additionalDirections = []direction{NW} + nextDirections = append(nextDirections, NW) case S: - additionalDirections = []direction{SW} + nextDirections = append(nextDirections, SW) } } - for _, dir := range additionalDirections { - log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir]))) - queue.Enqueue(ns[dir]) - _, ok := om.Get(ns[dir]) + for _, nextDirection := range nextDirections { + log.Debugf("adding %s to the queue", string(graph.valueAt(ns[nextDirection]))) + queue.Enqueue(ns[nextDirection]) + _, ok := om.Get(ns[nextDirection]) if !ok { - om.Set(ns[dir], struct{}{}) + om.Set(ns[nextDirection], struct{}{}) } } }