From 02443ef244c536c6fa40d1bb196c63d462667b8a Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 6 Dec 2024 23:17:44 +0000 Subject: [PATCH] move check is loop logic to top of loop --- day-06/internal/two/solve.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/day-06/internal/two/solve.go b/day-06/internal/two/solve.go index 643530b..f0c82a6 100644 --- a/day-06/internal/two/solve.go +++ b/day-06/internal/two/solve.go @@ -35,19 +35,18 @@ func Solve(buf []byte) (int, error) { p.y == 0 && p.direction == N || p.y == len(g.data)-1 && p.direction == S || p.x == len(g.data[p.y])-1 && p.direction == E) { - p = nextPoint(p) - if g.valueAt(p.x, p.y) == '#' || g.valueAt(p.x, p.y) == 'O' { - p.recalibrate() - } - _, ok := visited[p] if ok { log.Tracef("loop: \n%s\n", g.trace(visited)) isLoop <- true return } - visited[p] = struct{}{} + + p = nextPoint(p) + if g.valueAt(p.x, p.y) == '#' || g.valueAt(p.x, p.y) == 'O' { + p.recalibrate() + } } isLoop <- false }()