aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/18/solver.lisp
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-01-07 01:21:45 +0100
committerOscar Najera <hi@oscarnajera.com>2023-01-07 01:21:45 +0100
commit78d4103ee362dde65ca56136ed63f474d7a5a5e9 (patch)
tree989cc348ccea25211eb9af6ed1ae5691fc727ff6 /AoC2022/18/solver.lisp
parentd606533fb72fe3df2c69f3df9f74c5a7ccdf6dd2 (diff)
downloadscratch-78d4103ee362dde65ca56136ed63f474d7a5a5e9.tar.gz
scratch-78d4103ee362dde65ca56136ed63f474d7a5a5e9.tar.bz2
scratch-78d4103ee362dde65ca56136ed63f474d7a5a5e9.zip
Day 18
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")))))