From c5179fed617d7a5f1157c52ac6b96632deb4073d Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Thu, 11 Dec 2025 22:13:30 -0500 Subject: [PATCH] [p10] Add some comments --- p10/p10.org | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/p10/p10.org b/p10/p10.org index 7d5055e..59f91ab 100644 --- a/p10/p10.org +++ b/p10/p10.org @@ -1,5 +1,7 @@ #+title: Solution to p10 +This problem is pretty hard. I have not yet completely understood the +linear algebra behind it. #+begin_src emacs-lisp :results none (with-temp-buffer (insert-file-contents "input") @@ -18,15 +20,19 @@ (insert "))") (eval-buffer)) #+end_src -#+begin_src emacs-lisp :results none + +For part 1 we do not need the last item This is a linear algebra +problem in characteristic 2; we are essentially bruteforcing the +vector space; we easily succeed. +#+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 + (setq cleanedup-data (--map (cons (-map #'zero-one + (advent/split-string-into-char-list (car it))) + (cdr it)) + data)) -for part 1 we do not need the last item -#+begin_src emacs-lisp (setq machines (--map (-drop-last 1 it) cleanedup-data)) (defun to-bin (l) @@ -35,18 +41,21 @@ for part 1 we do not need the last item (defun to-mask (l) (-sum (--map (expt 2 it) l))) - (setq mask-machines (--map (cons (to-bin (car it)) (-map #'to-mask (cdr it))) machines)) + (setq mask-machines (--map (cons (to-bin (car it)) + (-map #'to-mask (cdr it))) + machines)) (-sum (-map (lambda (machine) - (-min (-map 'length (--filter (= (car machine) (apply 'logxor it)) - (-powerset (cdr machine)))))) + (-min (-map 'length (--filter (= (car machine) (apply 'logxor it)) + (-powerset (cdr machine)))))) mask-machines)) #+end_src #+RESULTS: : 7 + This approach blows the stack even for the test input #+begin_src emacs-lisp (setq machines (--map (-rotate 1 (cdr it)) data)) @@ -181,7 +190,7 @@ is a linear algebra problem. Gauss elimination to the rescue (--map (advent/dot it vector) matrix)) (defun solution-p (machine candidate) - (--every (= 0 it) (matrix-appl (matrix-buttons machine) (cons -1 candidate))) + (--every (= 0 it) (matrix-appl (matrix-buttons machine) (cons -1 candidate))) ) (setq current-machine nil) (defun solve--machine (machine)