|
|
|
@ -196,13 +196,10 @@ These are some auxiliary functions to create and deal with matrices |
|
|
|
| 38 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | |
|
|
|
| 38 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | |
|
|
|
| 61 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | |
|
|
|
| 61 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
#+RESULTS: |
|
|
|
(setq buttons nil) |
|
|
|
| 7 | 1 | 0 | 1 | 1 | 0 | |
|
|
|
(solve-well-ordered (matrix-buttons (fix-machine (nth 1 machines)))) |
|
|
|
| 5 | 0 | 0 | 0 | 1 | 1 | |
|
|
|
#+end_src |
|
|
|
| 12 | 1 | 1 | 0 | 1 | 1 | |
|
|
|
|
|
|
|
| 7 | 1 | 1 | 0 | 0 | 1 | |
|
|
|
|
|
|
|
| 2 | 1 | 0 | 1 | 0 | 1 | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -268,6 +265,7 @@ possibility |
|
|
|
(current-row (1- (length matrix)))) |
|
|
|
(current-row (1- (length matrix)))) |
|
|
|
(while (> last-used-button 0) |
|
|
|
(while (> last-used-button 0) |
|
|
|
(push last-used-button buttons) |
|
|
|
(push last-used-button buttons) |
|
|
|
|
|
|
|
(message (format "%d" (length soln))) |
|
|
|
(let* ((row (nth current-row matrix)) |
|
|
|
(let* ((row (nth current-row matrix)) |
|
|
|
(a (car row)) |
|
|
|
(a (car row)) |
|
|
|
(rrow (cdr row)) |
|
|
|
(rrow (cdr row)) |
|
|
|
@ -290,15 +288,21 @@ possibility |
|
|
|
(if (< max-soln 0) (list it) |
|
|
|
(if (< max-soln 0) (list it) |
|
|
|
(-map (lambda (candidate) (-replace-at button candidate it)) (-iota (1+ max-soln))))) |
|
|
|
(-map (lambda (candidate) (-replace-at button candidate it)) (-iota (1+ max-soln))))) |
|
|
|
soln) |
|
|
|
soln) |
|
|
|
|
|
|
|
; remove solutions that are not feasible |
|
|
|
|
|
|
|
soln (--filter (--every (>= it 0) (-map (lambda (row) |
|
|
|
|
|
|
|
(let ((correction (advent/dot it (cdr row)))) |
|
|
|
|
|
|
|
(- (car row) correction))) |
|
|
|
|
|
|
|
matrix)) |
|
|
|
|
|
|
|
soln) |
|
|
|
last-used-button button)))) |
|
|
|
last-used-button button)))) |
|
|
|
(setq soln (-non-nil (--map (when (= a (advent/dot it rrow)) it) soln)) |
|
|
|
(setq soln (--filter (= a (advent/dot it rrow)) soln) |
|
|
|
current-row (1- current-row))))) |
|
|
|
current-row (1- current-row))))) |
|
|
|
soln)) |
|
|
|
soln)) |
|
|
|
|
|
|
|
|
|
|
|
(defun minimal-pushes (machine) |
|
|
|
(defun minimal-pushes (machine) |
|
|
|
(-min (-map #'-sum (solve-row-reduced (row-reduce (matrix-buttons machine)))))) |
|
|
|
(-min (-map #'-sum (solve-row-reduced (row-reduce (matrix-buttons machine)))))) |
|
|
|
|
|
|
|
|
|
|
|
last-used-button |
|
|
|
|
|
|
|
#+end_src |
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
#+RESULTS: |
|
|
|
|