mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2026-04-13 12:33:36 +00:00
dfs explore functions return only bool
This commit is contained in:
@@ -16,8 +16,8 @@ func Solve(buf []byte) (int, error) {
|
||||
for _, dir := range dirs {
|
||||
log.Debugf("about to explore '%s' direction from robot location %v", string(dir), graph.robot)
|
||||
|
||||
stack, ok := explore(graph, graph.robot, directions(dir), newStack())
|
||||
if !ok {
|
||||
stack := newStack()
|
||||
if ok := explore(graph.robot, directions(dir), stack, graph); !ok {
|
||||
log.Debug("path ends with '#', continuing...")
|
||||
continue
|
||||
}
|
||||
@@ -39,19 +39,19 @@ func Solve(buf []byte) (int, error) {
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func explore(graph *graph, next point, direction direction, stack *stack) (*stack, bool) {
|
||||
func explore(next point, direction direction, stack *stack, g *graph) bool {
|
||||
ns := neighbours(next)
|
||||
|
||||
log.Debug(string(graph.valueAt(ns[direction])))
|
||||
log.Debug(string(g.valueAt(ns[direction])))
|
||||
|
||||
switch graph.valueAt(ns[direction]) {
|
||||
switch g.valueAt(ns[direction]) {
|
||||
case '#':
|
||||
return nil, false
|
||||
return false
|
||||
case '.':
|
||||
return stack, true
|
||||
return true
|
||||
case 'O':
|
||||
stack.Push(ns[direction])
|
||||
}
|
||||
|
||||
return explore(graph, ns[direction], direction, stack)
|
||||
return explore(ns[direction], direction, stack, g)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user