aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
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