From bed1a4d7d7b29af3af95c5dffd92e8203e7df0b6 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Wed, 10 Dec 2025 16:00:49 -0500 Subject: [PATCH] [p10] start --- p10/p10.org | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 p10/p10.org diff --git a/p10/p10.org b/p10/p10.org new file mode 100644 index 0000000..fcb3648 --- /dev/null +++ b/p10/p10.org @@ -0,0 +1,51 @@ +#+title: Solution to p10 + +#+begin_src emacs-lisp :results none + (with-temp-buffer + (insert-file-contents "input-test") + (advent/replace-multiple-regex-buffer + '(("," . " ") + ("^" . "(") + ("$" . ")") + ("\\[" . "\"") + ("\\]" . "\"") + ("{" . "(") + ("}" . ")") + )) + (goto-char (point-min)) + (insert "(setq data '(") + (goto-char (point-max)) + (insert "))") + (eval-buffer)) +#+end_src + +#+begin_src emacs-lisp + (defun zero-one (n) + (if (eq n ?#) 1 0)) + + (setq cleanedup-data (--map (cons (-map #'zero-one (advent/split-string-into-char-list (car it))) (cdr it)) data)) +#+end_src + +#+RESULTS: +| (0 1 1 0) | (3) | (1 3) | (2) | (2 3) | (0 2) | (0 1) | (3 5 4 7) | +| (0 0 0 1 0) | (0 2 3 4) | (2 3) | (0 4) | (0 1 2) | (1 2 3 4) | (7 5 12 7 2) | | +| (0 1 1 1 0 1) | (0 1 2 3 4) | (0 3 4) | (0 1 2 4 5) | (1 2) | (10 11 11 5 10 5) | | | + +for part 1 we do not need the last item +#+begin_src emacs-lisp + (setq machines (--map (-drop-last 1 it) cleanedup-data)) + + (defun init-machine (spec) + (setq machine (-repeat (length (car spec)) 0))) + + (defun toggle (n) + (logxor 0 1)) + + (defun toggle-button (button) + (setq machine (--map-indexed (if (-contains-p button it-index) (logxor it 1) it) machine))) + + (init-machine (car machines)) + + (toggle-button '(1)) + +#+end_src