diff --git a/p3/p3.org b/p3/p3.org new file mode 100644 index 0000000..3c4e31d --- /dev/null +++ b/p3/p3.org @@ -0,0 +1,31 @@ +#+title: Solution to p3 + +First load the data as a list of lists of numbers +#+begin_src emacs-lisp :results none + (with-temp-buffer + (insert-file-contents "input") + (advent/replace-multiple-regex-buffer + '(("\\(.\\)" . "\\1 ") + ("^" . "(") + ("$" . ")"))) + (goto-char (point-min)) + (insert "(setq data '(") + (goto-char (point-max)) + (insert "))") + (eval-buffer)) +#+end_src + +This is for part 1: +#+begin_src emacs-lisp + (defun joltage (bank) + (let* ((max-joltage (-max bank)) + (max-pos (1+ (-elem-index max-joltage bank)))) + (if (< max-pos (length bank)) + (+ (* 10 max-joltage) (-max (-drop max-pos bank))) + (+ (* 10 (-max (-drop-last 1 bank))) max-joltage)))) + + (-sum (-map #'joltage data)) +#+end_src + +#+RESULTS: +: 17405