[p10] minor improvements

master
Jacopo De Simoi 6 months ago
parent 43ba7e53f3
commit 3875ba2e76
  1. 22
      p10/p10.org

@ -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 |
| 61 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
#+RESULTS:
| 7 | 1 | 0 | 1 | 1 | 0 |
| 5 | 0 | 0 | 0 | 1 | 1 |
| 12 | 1 | 1 | 0 | 1 | 1 |
| 7 | 1 | 1 | 0 | 0 | 1 |
| 2 | 1 | 0 | 1 | 0 | 1 |
#+begin_src emacs-lisp
(setq buttons nil)
(solve-well-ordered (matrix-buttons (fix-machine (nth 1 machines))))
#+end_src
@ -268,6 +265,7 @@ possibility
(current-row (1- (length matrix))))
(while (> last-used-button 0)
(push last-used-button buttons)
(message (format "%d" (length soln)))
(let* ((row (nth current-row matrix))
(a (car row))
(rrow (cdr row))
@ -290,15 +288,21 @@ possibility
(if (< max-soln 0) (list it)
(-map (lambda (candidate) (-replace-at button candidate it)) (-iota (1+ max-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))))
(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)))))
soln))
(defun minimal-pushes (machine)
(-min (-map #'-sum (solve-row-reduced (row-reduce (matrix-buttons machine))))))
last-used-button
#+end_src
#+RESULTS:

Loading…
Cancel
Save