diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-02 22:33:06 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-02 22:33:06 +0100 |
commit | 225cbc55a4992e3b656129fe75e51a139bee2d07 (patch) | |
tree | e1cd8043596a883623b2b62a4b75a2458fec668a /2024 | |
parent | 5f8556807a6adae632f3646727a2bb1b16b68614 (diff) |
Add an Emacs Lisp solution
Diffstat (limited to '2024')
-rw-r--r-- | 2024/01/puzzle-1.el | 21 |
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 |