Created
December 15, 2022 00:23
-
-
Save Gavinok/1631fd138fc91a08a33c4b66afe15f39 to your computer and use it in GitHub Desktop.
Emacs lisp solution for day one of advent of code 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun cals-per-elf () | |
(with-temp-buffer | |
(progn (insert "((") | |
(insert-file-contents "~/res.txt") | |
(while (re-search-forward "^$" nil t) | |
(replace-match ")(" nil nil)) | |
(end-of-buffer)(insert "))") | |
(goto-char 0)) | |
(mapcar (lambda (food-carried) | |
(cl-reduce #'+ food-carried)) | |
(read (current-buffer))))) | |
(defun aoc-day1-part1 () | |
(cl-reduce #'max | |
(cals-per-elf))) | |
(defun aoc-day1-part1 () | |
(cl-reduce #'+ | |
(seq-take (cl-sort (cals-per-elf) | |
#'>) | |
3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the style!
I would take apply '+ instead of cl-reduce, but it's the same way I think
Peter