|
|
|
|
@ -18,12 +18,50 @@ First load the data as a list of cons cells (start . end) |
|
|
|
|
|
|
|
|
|
This is for part 1. Quite straightforward |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(-sum (--map (apply (car it) (cdr it)) |
|
|
|
|
(apply #'-zip-lists (-rotate 1 data)))) |
|
|
|
|
(-sum (-map #'eval (apply #'-zip-lists (-rotate 1 data)))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
#+RESULTS: |
|
|
|
|
: 4412382293768 |
|
|
|
|
|
|
|
|
|
For part 2, we need a different approach. let's transpose the whole buffer |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(with-temp-buffer |
|
|
|
|
(insert-file-contents "input") |
|
|
|
|
(goto-char (point-max)) |
|
|
|
|
(beginning-of-line) |
|
|
|
|
(kill-line) |
|
|
|
|
(backward-delete-char 1) |
|
|
|
|
(goto-char (point-min)) |
|
|
|
|
(yank) (insert "\n") |
|
|
|
|
(advent/replace-multiple-regex-buffer |
|
|
|
|
'( |
|
|
|
|
("^" . "\"") |
|
|
|
|
("$" . "\"") |
|
|
|
|
)) |
|
|
|
|
(goto-char (point-min)) |
|
|
|
|
(insert "(setq data '(") |
|
|
|
|
(goto-char (point-max)) |
|
|
|
|
(insert "))") |
|
|
|
|
(eval-buffer) |
|
|
|
|
(with-temp-buffer |
|
|
|
|
(apply #'insert (--map (apply 'string it) (apply #'-zip-lists (-map #'advent/split-string-into-char-list data)))) |
|
|
|
|
(advent/replace-multiple-regex-buffer |
|
|
|
|
'(("\\([*+]\\)" . ") (\\1 ")) |
|
|
|
|
) |
|
|
|
|
(goto-char (point-max)) |
|
|
|
|
(insert ")))") |
|
|
|
|
(goto-char (point-min)) |
|
|
|
|
(insert "(setq data2 '(") |
|
|
|
|
(delete-char 1) |
|
|
|
|
(eval-buffer))) |
|
|
|
|
#+end_src |
|
|
|
|
Then do the math |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(-sum (-map #'eval data2)) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
: 7858808482092 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|