diff --git a/advent-of-code-2018.asd b/advent-of-code-2018.asd index c2c9fc2..d99de5f 100644 --- a/advent-of-code-2018.asd +++ b/advent-of-code-2018.asd @@ -27,4 +27,5 @@ (:file "day17") (:file "day18") (:file "day19") - (:file "day23"))) + (:file "day23") + (:file "day25"))) diff --git a/day25.lisp b/day25.lisp new file mode 100644 index 0000000..62e1800 --- /dev/null +++ b/day25.lisp @@ -0,0 +1,17 @@ +;;;; day25.lisp + +(in-package :advent-of-code-2018) + +(defun day25-make-in-range-p (p1) + (lambda (p2) (<= (manhattan p1 p2) 3))) + +(defun day25 () + (loop + :for p :in (mapcar #'extract-integers (read-puzzlefile "input25.txt")) + :for sets := (list (list p)) :then (loop :for set :in sets + :if (some (lambda (p2) (in-range-p p p2)) set) + :append set :into in-range + :else + :collect set :into other + :finally (return (cons (cons p in-range) other))) + :finally (return (format t "There are ~a constellations.~%" (length sets)))))