mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
move check is loop logic to top of loop
This commit is contained in:
parent
08706ecc11
commit
02443ef244
@ -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
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user