advent-of-code-2024

My solutions to AoC 2024
Log | Files | Refs

commit 5cd36c441567ae4b5c7bd4bc399e39eea75e1206
parent ddf4527960184f991ca2d6abda4882b6c351312e
Author: Lukas Henkel <lh@entf.net>
Date:   Wed, 18 Dec 2024 07:34:45 +0100

Reverse task 2

This way is much faster

Diffstat:
Msrc/day-18.lisp | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/day-18.lisp b/src/day-18.lisp @@ -24,9 +24,14 @@ until (null line) collect (parse-coordinate line))) +(declaim (inline fall-byte unfall-byte)) + (defun fall-byte (map position) (setf (map-cell map position) #\#)) +(defun unfall-byte (map position) + (setf (map-cell map position) #\.)) + (defun draw-map (map visited) (loop for y from 0 below *height* do (loop for x from 0 below *width* @@ -57,8 +62,10 @@ (defun task-2 (map coordinates) (loop for byte in coordinates - do (fall-byte map byte) - unless (bfs map) + do (fall-byte map byte)) + (loop for byte in (nreverse coordinates) + do (unfall-byte map byte) + when (bfs map) do (return byte))) (defun day-18 (input)