mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +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 == 0 && p.direction == N ||
|
||||||
p.y == len(g.data)-1 && p.direction == S ||
|
p.y == len(g.data)-1 && p.direction == S ||
|
||||||
p.x == len(g.data[p.y])-1 && p.direction == E) {
|
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]
|
_, ok := visited[p]
|
||||||
if ok {
|
if ok {
|
||||||
log.Tracef("loop: \n%s\n", g.trace(visited))
|
log.Tracef("loop: \n%s\n", g.trace(visited))
|
||||||
isLoop <- true
|
isLoop <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
visited[p] = struct{}{}
|
visited[p] = struct{}{}
|
||||||
|
|
||||||
|
p = nextPoint(p)
|
||||||
|
if g.valueAt(p.x, p.y) == '#' || g.valueAt(p.x, p.y) == 'O' {
|
||||||
|
p.recalibrate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isLoop <- false
|
isLoop <- false
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user