aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-12-02 00:07:05 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-12-02 00:31:06 +0000
commit1ddc695cb9e0c0d8dfe87ade4981142155cd91bf (patch)
treec71c1098dfec63dfa290d2337e6ec292e38a26be /2024
parent3784d148c74de4eede1fb2d01edb2ffe332d3574 (diff)
downloadadvent-of-code-1ddc695cb9e0c0d8dfe87ade4981142155cd91bf.tar.gz
advent-of-code-1ddc695cb9e0c0d8dfe87ade4981142155cd91bf.tar.bz2
advent-of-code-1ddc695cb9e0c0d8dfe87ade4981142155cd91bf.zip
Belated 2024 first puzzle solution
Diffstat (limited to '2024')
-rw-r--r--2024/puzzle-1.lisp15
-rw-r--r--2024/util.lisp11
2 files changed, 26 insertions, 0 deletions
diff --git a/2024/puzzle-1.lisp b/2024/puzzle-1.lisp
new file mode 100644
index 0000000..ad667d4
--- /dev/null
+++ b/2024/puzzle-1.lisp
@@ -0,0 +1,15 @@
+(load "util.lisp")
+
+(--> (uiop:read-file-lines "1-input")
+ (loop for line in _
+ for x = (search " " line)
+ collect (parse-integer (subseq line 0 x)) into left
+ collect (parse-integer (subseq line (+ x 3))) into right
+ finally (return (list (sort left #'<) (sort right #'<))))
+ (format t "Round 1: ~a~%Round 2: ~a~%"
+ (loop for x in (car _)
+ for y in (cadr _)
+ sum (abs (- y x)))
+ (loop for item in (car _)
+ for count = (count item (cadr _))
+ sum (* item count))))
diff --git a/2024/util.lisp b/2024/util.lisp
new file mode 100644
index 0000000..f9b1d86
--- /dev/null
+++ b/2024/util.lisp
@@ -0,0 +1,11 @@
+(defmacro --> (first &rest functions)
+ (if (null functions)
+ first
+ `(let* ,(loop :for f :in (cons first functions)
+ appending `((_ ,f)))
+ _)))
+
+(defun zip (a b)
+ (loop for i in a
+ for j in b
+ collect (cons i j)))