Skip to content

Commit

Permalink
Fixes to day 15, 17, 20
Browse files Browse the repository at this point in the history
  • Loading branch information
abraemer committed Mar 18, 2019
1 parent e107ac2 commit 323a072
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions advent-of-code-2018.asd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
(:file "day12")
(:file "day13")
(:file "day14")
(:file "day15")
(:file "day16")
(:file "day17")
(:file "day18")
Expand Down
9 changes: 5 additions & 4 deletions day15.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion day17.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions day20.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit 323a072

Please sign in to comment.