From 323a0725b0ac54ac80c5aee04952993cc28f1e2f Mon Sep 17 00:00:00 2001 From: Adrian Braemer <11058200+NobodysHero@users.noreply.github.com> Date: Mon, 18 Mar 2019 23:39:33 +0100 Subject: [PATCH] Fixes to day 15, 17, 20 --- advent-of-code-2018.asd | 1 + day15.lisp | 9 +++++---- day17.lisp | 2 +- day20.lisp | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/advent-of-code-2018.asd b/advent-of-code-2018.asd index 19caf3e..2abcd09 100644 --- a/advent-of-code-2018.asd +++ b/advent-of-code-2018.asd @@ -23,6 +23,7 @@ (:file "day12") (:file "day13") (:file "day14") + (:file "day15") (:file "day16") (:file "day17") (:file "day18") diff --git a/day15.lisp b/day15.lisp index 239438f..36e0006 100644 --- a/day15.lisp +++ b/day15.lisp @@ -75,9 +75,10 @@ filled)) (defun day15-turn! (board unit position attack-power) - (let ((targets (mapcar #'first - (remove nil (day15-list-pos+unit board) - :key (day15-target-selector unit)))) + (let* ((target-selector (day15-target-selector unit)) + (targets (mapcar #'first + (remove nil (day15-list-pos+unit board) + :key (lambda (pos+unit) (funcall target-selector (second pos+unit)))))) (distances (day15-flood board position))) (when targets (let ((target-field @@ -146,7 +147,7 @@ (format t "Score: ~a~%~%" (* rounds total-hp)))) (loop :for elf-power := 4 :then (1+ elf-power) :until (loop :with board := (day15-copy-board initial-board) - :with elves := (remove-if #'day15-goblin-p (mapcar #'second (day15-list-pos+unit))) + :with elves := (remove-if #'day15-goblin-p (mapcar #'second (day15-list-pos+unit board))) :while (every #'day15-alive-p elves) :while (day15-round! board elf-power) :count t :into rounds diff --git a/day17.lisp b/day17.lisp index 35a79d5..b441c75 100644 --- a/day17.lisp +++ b/day17.lisp @@ -38,7 +38,7 @@ board) (defun day17-initialize-board (input) - (destructuring-bind (raw-min-x max-x min-y max-y) (day17-bbox inp) + (destructuring-bind (raw-min-x max-x min-y max-y) (day17-bbox input) (let* ((width (+ 3 (- max-x raw-min-x)));pad-x (height (+ 1 (- max-y min-y))) (min-x (1- raw-min-x)) diff --git a/day20.lisp b/day20.lisp index 75e3516..825ab62 100644 --- a/day20.lisp +++ b/day20.lisp @@ -68,13 +68,13 @@ (defun day20 () (let ((edges (day20-build-graph (day20-parse-file)))) - (loop :with open := (make-instance 'fibonacci-heap :key #'car) + (loop :with open := (make-instance 'cl-heap:fibonacci-heap :key #'car) :with closed := (make-hash-table) - :for (depth . node) := (cons 0 #C(0 0)) :then (pop-heap open) + :for (depth . node) := (cons 0 #C(0 0)) :then (cl-heap:pop-heap open) :count (>= depth 1000) :into far-away :do (setf (gethash node closed) t) :do (dolist (new (gethash node edges)) (unless (gethash new closed nil) - (add-to-heap open (cons (1+ depth) new)))) - :while (> (heap-size open) 0) + (cl-heap:add-to-heap open (cons (1+ depth) new)))) + :while (> (cl-heap:heap-size open) 0) :finally (format t "The furthest room is ~a doors away and there a total of ~a rooms 1000 doors or more away.~%" depth far-away))))