From c82521a8c8d39f9afc9dc3753c4b835c75f8cbd3 Mon Sep 17 00:00:00 2001 From: StarlitGhost <679547+StarlitGhost@users.noreply.github.com> Date: Wed, 18 Dec 2024 23:43:41 +0000 Subject: [PATCH] [2024/18] p1 & p2 solved --- .aoc_tiles/tiles/2024/18.png | Bin 0 -> 5380 bytes 2024/18/example | 25 +++++++++++++++++ 2024/18/script.py | 51 +++++++++++++++++++++++++++++++++++ README.md | 7 +++-- 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 .aoc_tiles/tiles/2024/18.png create mode 100644 2024/18/example create mode 100644 2024/18/script.py diff --git a/.aoc_tiles/tiles/2024/18.png b/.aoc_tiles/tiles/2024/18.png new file mode 100644 index 0000000000000000000000000000000000000000..bb4fda1bddf1c02d33967516d73aa6e4c9c0edc6 GIT binary patch literal 5380 zcmV+f75nOmP)?opG02M?~5J6xO>1CJg-yai(+1WO;Ww!bJ!H+$A<~(!W^X!>3r@Sv? z8!ro=`q|Q) zF-al#6q!QR+AY4<-1U3O{j)b8$dxLGuI*!9+IU$8@&N#cg@gzNAwt2}JlD<3 z$V>@U3Y#jm9br3wJj;{s!Yyt0!*vWA2(7#8M5VLx`(E37Mb zn^*tmEP^mbCj|fVxh!vYE&zDDb2l!|S^R09nXKgDh*rjcAdE%hh6MY#umA2m0DSb~ zSTA?3^?2>d&PE=EDwXTj^E2Xuk|X>o>RSOo=)rqs+VDxKQNA8-HKNWf zc_jd_W#tq!XIr;q!r%7z`FQ4UT!JF zsBd+5;{*!@9M<4l(S($++|-Cu*Xymv3wEX|AoErz7K`()R;yHMEF~*36ab1cwDK!kPCxyxyjkxbDykCU)2EM!wkoe3+S!P( zP*%A@^{8u*KEzkRV8Ca~Ci{C0ma9^$5e8%7_#`ZaVPG6#4321J44r+_ZNJ~dr$h#L z0>Fmdg-bp^{-CwTvb=VvDlq&g#Iw3_26HNus!>Bi;zNa4%Evz!?ai-<3-;Nva!TO9 z1I}bPqLm3?A{sv`7Lx%0SMD?efL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?`NsR{G{QXSIvld8#}uHt^`R8U~Z2{Vhp2 zpOsyZS7W2!)}uGJ9=)NDRn*?Q`s8vu?L*HODo9Gue1F33y4&pU&}{`2)u zjViBey;ZNnBM%uktCd}l*D`+IV}rc|yxeDuj2#gdwEQb0y_!Bav6Wqr*D`+ImpnOa z>WG+XQRk|!&y<_gT{*XvU67YCa?Kw4SqXT|>wLVH@$>E|wSCM>8?OcYygN{BAM?`2 ii`aw}#baJ4=KX)$y>*H#soyvN0000 list[tuple]: + return list(cell for cell in grid.neighbours(pos, diagonal=False) + if grid[cell] != '#') + + +def main(): + inputs = aoc.read_lines() + + memory = Grid(["."]) + memory.expand_for(Vec2(aoc.args.size-1, aoc.args.size-1), fill='.') + + bytes_ = list(Vec2.from_str(line, split=',') for line in inputs) + num_bytes = min(len(bytes_), aoc.args.bytes) + for byte in bytes_[:num_bytes]: + memory[byte] = '#' + + start = (0, 0) + end = (memory.width()-1, memory.height()-1) + + neighbour_func = partial(neighbours, grid=memory) + came_from, _, _ = a_star(start, end, neighbours=neighbour_func) + path = reconstruct_path(came_from, start, end) + + if aoc.args.verbose or aoc.args.progress: + overlays = [{pos: 'O' for pos in path}, + {start: 'S', end: 'E'},] + print(memory.render_with_overlays(overlays)) + print(f"p1: {len(path)-1}") + + for byte in bytes_[num_bytes:]: + memory[byte] = '#' + came_from, _, _ = a_star(start, end, neighbours=neighbour_func) + path = reconstruct_path(came_from, start, end) + if len(path) == 0: + print(f"p2: {byte[0]},{byte[1]}") + break + + +if __name__ == "__main__": + main() diff --git a/README.md b/README.md index 7c3ef39..c4983f7 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code

- Advent of Code - 193/484 ⭐ + Advent of Code - 195/486 ⭐

- 2024 - 32 ⭐ - Python + 2024 - 34 ⭐ - Python

@@ -59,6 +59,9 @@ My solutions to the yearly Advents of Code + + +

2023 - 47 ⭐ - Python