Skip to content

Instantly share code, notes, and snippets.

@Gavinok
Created December 15, 2022 00:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gavinok/1631fd138fc91a08a33c4b66afe15f39 to your computer and use it in GitHub Desktop.
Save Gavinok/1631fd138fc91a08a33c4b66afe15f39 to your computer and use it in GitHub Desktop.
Emacs lisp solution for day one of advent of code 2022
(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)))
@macropeter
Copy link

I like the style!
I would take apply '+ instead of cl-reduce, but it's the same way I think
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment