|
|
|
|
@ -18,34 +18,33 @@ |
|
|
|
|
(insert "))") |
|
|
|
|
(eval-buffer)) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(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 |
|
|
|
|
#+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))) |
|
|
|
|
(defun to-bin (l) |
|
|
|
|
(-sum (--map-indexed (* it (expt 2 it-index)) l))) |
|
|
|
|
|
|
|
|
|
(init-machine (car machines)) |
|
|
|
|
(defun to-mask (l) |
|
|
|
|
(-sum (--map (expt 2 it) l))) |
|
|
|
|
|
|
|
|
|
(toggle-button '(1)) |
|
|
|
|
(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)))))) |
|
|
|
|
mask-machines)) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
: 7 |
|
|
|
|
|