From 7c4dbe48dad69ecdc3d1d82cc2928ce38d16ba6a Mon Sep 17 00:00:00 2001 From: StarlitGhost <679547+StarlitGhost@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:59:13 +0000 Subject: [PATCH] [2024/6] p2 solved (slow - takes 5m30s) --- .aoc_tiles/tiles/2024/06.png | Bin 6286 -> 6424 bytes 2024/6/script.py | 81 +++++++++++++++++++++++++++++++---- README.md | 4 +- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/.aoc_tiles/tiles/2024/06.png b/.aoc_tiles/tiles/2024/06.png index 77809840cc8b092229e2d897941c72903452a51b..5c44581b2bc1c9cd6f70d942394162f62807d734 100644 GIT binary patch literal 6424 zcmX9@1zc0#`yL=5BLt-cLHwf9;OOp@jxiW8x{ASHsN zz<>UK_w(L3=bm%xecyAQ=eh57v{cA}3_t(?K(3~$sE6D4;Z~db__(dc#*QffK)<4< zC}-fGbzlZJ)wgd7s^$yl*+<&Ed)x4=VNG6XuWZWMWMSUqK=@7Z`t)}Lq(pZ7jPIe* z8??Z*6B=w{Qj6g~1o9eD6WS0P6Ou?+sNfHSIZhxp~wR+{a!GCAF z!B@_$yUJzox8(D6(gMqM*aLXhu1Gf;WA|1ed`&Hs+(X3@Er zY|x7VI%JV{T#Yv;C!_dxTS)Qd6iP74EcO3e&pqD-gbdnUMJu&hjZHeVd6u}Ww+?P@ zJzS7?BGKf~M6Nat$AMYgVJWX{I;WlbK*uD~eJ5bR5n)D1j zC`qv}k$$kttr2?~C?>Ym8(TG^z5P|_J|OnNAK+co^b{8{pW z)-X}XlG~7+ex2{x^A=>+(iBJF!s{ghNYF><(j*C>&DD5+{bvYl(NlC?UMucd^U{c&wW=MF4BW3wF`o;Bce9m{N?(ap8$`EAyDffwwpsfPA^eQ{ z6Szn@L*i;Ta7mGjD4@=@?w!}27ZoO@-=Z{&xv05=<*`cITdCnL2NB-g0sju+Kcg$WXdorU)ALT=63E^1Tm4S}F%F*up;9>vPWNg=KE} zF%&5^%}>G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qoM6N<$ Ef{+PDF#rGn diff --git a/2024/6/script.py b/2024/6/script.py index fb6a754..b5def3a 100644 --- a/2024/6/script.py +++ b/2024/6/script.py @@ -7,7 +7,7 @@ def move(pos: tuple, dir_: Dir, grid: Grid) -> tuple[tuple, Dir]: next_pos = pos + Vec2(dir_) # out of bounds or open, return next position - if not grid.in_bounds(next_pos) or not grid[next_pos] == '#': + if not grid.in_bounds(next_pos) or not grid[next_pos] in '#O': return next_pos.as_tuple(), dir_ # obstacle, rotate right 90 degrees @@ -15,20 +15,85 @@ def move(pos: tuple, dir_: Dir, grid: Grid) -> tuple[tuple, Dir]: return pos, dir_.turn_right() -def main(): - grid = Grid(aoc.read_lines()) - - pos = grid.find('^') - dir_ = Dir.UP - +def simulate(pos: tuple, dir_: Dir, grid: Grid) -> tuple[set, list, bool]: visited = set() visited.add(pos) + path = [] + path.append((pos, dir_)) + loops = False + while grid.in_bounds(pos): pos, dir_ = move(pos, dir_, grid) visited.add(pos) + if path[-1][0] == pos: + path.append((pos, dir_)) + path.append((pos, None)) + elif (pos, dir_) in path: + loops = True + break + else: + path.append((pos, dir_)) + + return visited, path, loops + + +def print_path(grid: Grid, path: list, start_pos: tuple): + dir_chars = { + Dir.UP: '|', + Dir.DOWN: '|', + Dir.LEFT: '-', + Dir.RIGHT: '-', + None: '+', + } + print(grid.render_with_overlays([{pos: dir_chars[dir_] for pos, dir_ in path}, + {start_pos: '^'}])) + + +def main(): + grid = Grid(aoc.read_lines()) + + start_pos = grid.find('^') + dir_ = Dir.UP + + visited, path, _ = simulate(start_pos, dir_, grid) + + # print(grid.render_with_overlays([{pos: 'X' for pos in visited}])) + # print("p1:", len(visited) - 1) + + # print_path(grid, path, start_pos) + + loop_obstacles = set() + tried_obstacles = set() + path = [p for p in path if p[1] is not None] + + # try placing an obstacle at every position along our initial path + for i, pair in enumerate(path): + pos = pair[0] + + # skip the start position, out-of-bounds, and previously tried obstacles + if pos == start_pos or not grid.in_bounds(pos) or pos in tried_obstacles: + continue + + # place the obstacle + grid[pos] = 'O' + tried_obstacles.add(pos) + + # start pathing from just before the newly placed obstacle + new_start_pos, new_dir = path[i-1] if path[i-1][0] != pos else path[i-2] + + new_visited, new_path, loops = simulate(new_start_pos, new_dir, grid) + + # track obstacles that cause loops + if loops: + loop_obstacles.add(pos) + # print_path(grid, new_path, new_start_pos) + print(f"{i}/{len(path)} {len(loop_obstacles)}") + + # remove the current obstacle so we can try the next one + grid[pos] = '.' - print(grid.render_with_overlays([{pos: 'X' for pos in visited}])) print("p1:", len(visited) - 1) + print("p2:", len(loop_obstacles)) if __name__ == "__main__": diff --git a/README.md b/README.md index 5a86a3d..df9a857 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

- Advent of Code - 172/462 ⭐ + Advent of Code - 173/462 ⭐

- 2024 - 11 ⭐ - Python + 2024 - 12 ⭐ - Python