[p10] Add some comments

master
Jacopo De Simoi 3 months ago
parent c82fbdebcf
commit c5179fed61
  1. 27
      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)

Loading…
Cancel
Save