[p10] Add some comments

master
Jacopo De Simoi 6 months ago
parent c82fbdebcf
commit c5179fed61
  1. 21
      p10/p10.org

@ -1,5 +1,7 @@
#+title: Solution to p10 #+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 #+begin_src emacs-lisp :results none
(with-temp-buffer (with-temp-buffer
(insert-file-contents "input") (insert-file-contents "input")
@ -18,15 +20,19 @@
(insert "))") (insert "))")
(eval-buffer)) (eval-buffer))
#+end_src #+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) (defun zero-one (n)
(if (eq n ?#) 1 0)) (if (eq n ?#) 1 0))
(setq cleanedup-data (--map (cons (-map #'zero-one (advent/split-string-into-char-list (car it))) (cdr it)) data)) (setq cleanedup-data (--map (cons (-map #'zero-one
#+end_src (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)) (setq machines (--map (-drop-last 1 it) cleanedup-data))
(defun to-bin (l) (defun to-bin (l)
@ -35,7 +41,9 @@ for part 1 we do not need the last item
(defun to-mask (l) (defun to-mask (l)
(-sum (--map (expt 2 it) 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 (-sum
(-map (lambda (machine) (-map (lambda (machine)
@ -47,6 +55,7 @@ for part 1 we do not need the last item
#+RESULTS: #+RESULTS:
: 7 : 7
This approach blows the stack even for the test input This approach blows the stack even for the test input
#+begin_src emacs-lisp #+begin_src emacs-lisp
(setq machines (--map (-rotate 1 (cdr it)) data)) (setq machines (--map (-rotate 1 (cdr it)) data))

Loading…
Cancel
Save