aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/18/solver.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/18/solver.lisp')
-rw-r--r--AoC2022/18/solver.lisp20
1 files changed, 20 insertions, 0 deletions
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")))))