From 78d4103ee362dde65ca56136ed63f474d7a5a5e9 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sat, 7 Jan 2023 01:21:45 +0100 Subject: Day 18 --- AoC2022/18/solver.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 AoC2022/18/solver.lisp (limited to 'AoC2022/18/solver.lisp') diff --git a/AoC2022/18/solver.lisp b/AoC2022/18/solver.lisp new file mode 100644 index 0000000..05c0102 --- /dev/null +++ b/AoC2022/18/solver.lisp @@ -0,0 +1,20 @@ +(ql:quickload '(fiveam uiop)) + +(defun distance-1 (a b) + (apply #'+ + (mapcar (lambda (e1 e2) + (abs (- e1 e2))) a b))) + +(defun surface (cubes) + (loop for a in cubes + sum (- 6 (loop for b in cubes + count (= 1 (distance-1 a b)))))) + +(defun parse-coords (filename) + (mapcar (lambda (l) + (mapcar #'parse-integer (uiop:split-string l :separator ","))) + (uiop:read-file-lines filename))) + +(fiveam:test solutions + (fiveam:is (= 64 (surface (parse-coords "eg-in")))) + (fiveam:is (= 4474 (surface (parse-coords "input"))))) -- cgit v1.2.3