diff --git a/25/main.go b/25/main.go index 6c1bb79..50d5aca 100644 --- a/25/main.go +++ b/25/main.go @@ -49,7 +49,7 @@ func (f *floor) Print() { func (f *floor) Step() bool { f.steps++ - movedThisStep := map[coord]struct{}{} + moved := false toMove := map[coord]coord{} for y := 0; y < f.height; y++ { for x := 0; x < f.width; x++ { @@ -58,16 +58,15 @@ func (f *floor) Step() bool { if x >= f.width { x = 0 } - next := coord{x: x, y: y} - if _, ok := movedThisStep[current]; !ok && f.m[current] == '>' && f.m[next] == '.' { - toMove[current] = next + if f.m[current] == '>' && f.m[coord{x: x, y: y}] == '.' { + toMove[current] = coord{x: x, y: y} + moved = true } } } for current, next := range toMove { f.m[next] = f.m[current] f.m[current] = '.' - movedThisStep[next] = struct{}{} } toMove = map[coord]coord{} for y := 0; y < f.height; y++ { @@ -77,18 +76,17 @@ func (f *floor) Step() bool { if y >= f.height { y = 0 } - next := coord{x: x, y: y} - if _, ok := movedThisStep[current]; !ok && f.m[current] == 'v' && f.m[next] == '.' { - toMove[current] = next + if f.m[current] == 'v' && f.m[coord{x: x, y: y}] == '.' { + toMove[current] = coord{x: x, y: y} + moved = true } } } for current, next := range toMove { f.m[next] = f.m[current] f.m[current] = '.' - movedThisStep[next] = struct{}{} } - return len(movedThisStep) > 0 + return moved } func partOne() {