From 12c88f0db10d4d0e2e4180999b1cc7c672445bd4 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sat, 6 Dec 2025 10:15:56 -0500 Subject: [PATCH] [p6] part2 done --- p6/p6.org | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/p6/p6.org b/p6/p6.org index 9eaa9ee..5c52987 100644 --- a/p6/p6.org +++ b/p6/p6.org @@ -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 +