aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-02 22:33:06 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-02 22:33:06 +0100
commit225cbc55a4992e3b656129fe75e51a139bee2d07 (patch)
treee1cd8043596a883623b2b62a4b75a2458fec668a /2024
parent5f8556807a6adae632f3646727a2bb1b16b68614 (diff)
Add an Emacs Lisp solution
Diffstat (limited to '2024')
-rw-r--r--2024/01/puzzle-1.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/2024/01/puzzle-1.el b/2024/01/puzzle-1.el
new file mode 100644
index 0000000..cd8853e
--- /dev/null
+++ b/2024/01/puzzle-1.el
@@ -0,0 +1,21 @@
+(defun solve (input-file)
+ (let* ((nums (with-temp-buffer
+ (insert-file-contents-literally input-file)
+ (goto-char (point-min))
+ (save-excursion
+ (insert ?\[)
+ (goto-char (point-max))
+ (insert ?\]))
+ (read (current-buffer))))
+ (num-count (length nums)))
+ (cl-loop for i from 0 below num-count
+ if (cl-evenp i)
+ collect (aref nums i) into xs
+ else
+ collect (aref nums i) into ys
+ finally return (thread-last
+ (seq-mapn #'- (sort xs) (sort ys))
+ (mapcar #'abs)
+ (apply #'+)))))
+
+(message "%d" (solve "input")) \ No newline at end of file