Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from Gavinok/AOC-d1.el
Created December 21, 2022 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarte/b50d1023fab4449d819972aed7a705bb to your computer and use it in GitHub Desktop.
Save jgarte/b50d1023fab4449d819972aed7a705bb 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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment