move check is loop logic to top of loop

This commit is contained in:
onyx-and-iris 2024-12-06 23:17:44 +00:00
parent 08706ecc11
commit 02443ef244

View File

@ -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
}()