diff --git a/p10/p10.org b/p10/p10.org index 4d5862b..474ec27 100644 --- a/p10/p10.org +++ b/p10/p10.org @@ -201,18 +201,20 @@ These are some auxiliary functions to create and deal with matrices #+begin_src emacs-lisp - (solve-well-ordered-chunks (-distinct (matrix-buttons (fix-machine (nth 2 machines)))) + (solve-well-ordered-chunks (-distinct (matrix-buttons (fix-machine (nth 7 machines)))) ) #+end_src #+RESULTS: -| 20 | 9 | 17 | 0 | 4 | 0 | 20 | 19 | +| 19 | 16 | 12 | 11 | 0 | 8 | 14 | 3 | 8 | #+begin_src emacs-lisp (setq rainbow (-annotate (lambda (n) (--map (mod n it) '(2 3 5 7))) (-iota (* 2 3 5 7)))) - (let* ((machine (nth 4 machines)) - (matrix (-distinct (matrix-buttons (fix-machine machine)))) + (-sum + (let ((machine-id 0)) + (-each machines (lambda (machine) + (let* ((matrix (-distinct (matrix-buttons (fix-machine machine)))) (solmod (--map (solve-well-ordered-chunks-mod matrix it) '(2 3 5 7))) (solns nil) (numcand (apply '* (-map 'length solmod))) @@ -227,95 +229,57 @@ These are some auxiliary functions to create and deal with matrices (-each (cadddr solmod) (lambda (d) (let ((cand (--map (cdr (assoc it rainbow)) (-zip-lists a b c d)))) - (message (format "Verifying %d / %d - found %d" (setq count (1+ count)) numcand (length solns))) + (message (format "machine %d. Verifying %d / %d - found %d" machine-id (setq count (1+ count)) numcand (length solns))) (when (test-soln matrix cand) (push cand solns))))))))))) - solns) + (setq machine-id (1+ machine-id)) + (-min (-map '-sum solns)) + ) + + ) + + )) + ) #+end_src -#+RESULTS: -| 17 | 6 | 7 | 22 | 9 | 2 | 20 | 14 | 5 | 5 | -| 9 | 10 | 15 | 16 | 9 | 0 | 24 | 8 | 1 | 11 | -| 21 | 4 | 3 | 28 | 9 | 0 | 18 | 14 | 7 | 5 | -| 9 | 10 | 15 | 10 | 9 | 6 | 24 | 14 | 1 | 5 | -| 13 | 8 | 11 | 16 | 9 | 4 | 22 | 14 | 3 | 5 | -| 17 | 6 | 7 | 24 | 9 | 0 | 20 | 12 | 5 | 7 | -| 17 | 6 | 7 | 18 | 9 | 6 | 20 | 18 | 5 | 1 | -| 9 | 10 | 15 | 12 | 9 | 4 | 24 | 12 | 1 | 7 | -| 21 | 4 | 3 | 24 | 9 | 4 | 18 | 18 | 7 | 1 | -| 9 | 10 | 15 | 6 | 9 | 10 | 24 | 18 | 1 | 1 | -| 13 | 8 | 11 | 18 | 9 | 2 | 22 | 12 | 3 | 7 | -| 13 | 8 | 11 | 12 | 9 | 8 | 22 | 18 | 3 | 1 | -| 17 | 6 | 7 | 20 | 9 | 4 | 20 | 16 | 5 | 3 | -| 9 | 10 | 15 | 14 | 9 | 2 | 24 | 10 | 1 | 9 | -| 21 | 4 | 3 | 26 | 9 | 2 | 18 | 16 | 7 | 3 | -| 9 | 10 | 15 | 8 | 9 | 8 | 24 | 16 | 1 | 3 | -| 13 | 8 | 11 | 20 | 9 | 0 | 22 | 10 | 3 | 9 | -| 13 | 8 | 11 | 14 | 9 | 6 | 22 | 16 | 3 | 3 | -| 11 | 9 | 13 | 13 | 9 | 5 | 23 | 14 | 2 | 5 | -| 15 | 7 | 9 | 19 | 9 | 3 | 21 | 14 | 4 | 5 | -| 7 | 11 | 17 | 13 | 9 | 1 | 25 | 8 | 0 | 11 | -| 19 | 5 | 5 | 25 | 9 | 1 | 19 | 14 | 6 | 5 | -| 7 | 11 | 17 | 7 | 9 | 7 | 25 | 14 | 0 | 5 | -| 11 | 9 | 13 | 15 | 9 | 3 | 23 | 12 | 2 | 7 | -| 23 | 3 | 1 | 27 | 9 | 3 | 17 | 18 | 8 | 1 | -| 11 | 9 | 13 | 9 | 9 | 9 | 23 | 18 | 2 | 1 | -| 15 | 7 | 9 | 21 | 9 | 1 | 21 | 12 | 4 | 7 | -| 15 | 7 | 9 | 15 | 9 | 7 | 21 | 18 | 4 | 1 | -| 7 | 11 | 17 | 9 | 9 | 5 | 25 | 12 | 0 | 7 | -| 19 | 5 | 5 | 21 | 9 | 5 | 19 | 18 | 6 | 1 | -| 7 | 11 | 17 | 3 | 9 | 11 | 25 | 18 | 0 | 1 | -| 11 | 9 | 13 | 17 | 9 | 1 | 23 | 10 | 2 | 9 | -| 23 | 3 | 1 | 29 | 9 | 1 | 17 | 16 | 8 | 3 | -| 11 | 9 | 13 | 11 | 9 | 7 | 23 | 16 | 2 | 3 | -| 15 | 7 | 9 | 17 | 9 | 5 | 21 | 16 | 4 | 3 | -| 7 | 11 | 17 | 11 | 9 | 3 | 25 | 10 | 0 | 9 | -| 19 | 5 | 5 | 23 | 9 | 3 | 19 | 16 | 6 | 3 | -| 7 | 11 | 17 | 5 | 9 | 9 | 25 | 16 | 0 | 3 | -| 17 | 6 | 7 | 19 | 9 | 5 | 20 | 17 | 5 | 2 | -| 9 | 10 | 15 | 13 | 9 | 3 | 24 | 11 | 1 | 8 | -| 21 | 4 | 3 | 25 | 9 | 3 | 18 | 17 | 7 | 2 | -| 9 | 10 | 15 | 7 | 9 | 9 | 24 | 17 | 1 | 2 | -| 13 | 8 | 11 | 19 | 9 | 1 | 22 | 11 | 3 | 8 | -| 13 | 8 | 11 | 13 | 9 | 7 | 22 | 17 | 3 | 2 | -| 17 | 6 | 7 | 21 | 9 | 3 | 20 | 15 | 5 | 4 | -| 21 | 4 | 3 | 27 | 9 | 1 | 18 | 15 | 7 | 4 | -| 9 | 10 | 15 | 9 | 9 | 7 | 24 | 15 | 1 | 4 | -| 9 | 10 | 15 | 15 | 9 | 1 | 24 | 9 | 1 | 10 | -| 13 | 8 | 11 | 15 | 9 | 5 | 22 | 15 | 3 | 4 | -| 17 | 6 | 7 | 23 | 9 | 1 | 20 | 13 | 5 | 6 | -| 17 | 6 | 7 | 17 | 9 | 7 | 20 | 19 | 5 | 0 | -| 9 | 10 | 15 | 11 | 9 | 5 | 24 | 13 | 1 | 6 | -| 21 | 4 | 3 | 23 | 9 | 5 | 18 | 19 | 7 | 0 | -| 9 | 10 | 15 | 5 | 9 | 11 | 24 | 19 | 1 | 0 | -| 13 | 8 | 11 | 17 | 9 | 3 | 22 | 13 | 3 | 6 | -| 13 | 8 | 11 | 11 | 9 | 9 | 22 | 19 | 3 | 0 | -| 11 | 9 | 13 | 16 | 9 | 2 | 23 | 11 | 2 | 8 | -| 23 | 3 | 1 | 28 | 9 | 2 | 17 | 17 | 8 | 2 | -| 11 | 9 | 13 | 10 | 9 | 8 | 23 | 17 | 2 | 2 | -| 15 | 7 | 9 | 22 | 9 | 0 | 21 | 11 | 4 | 8 | -| 15 | 7 | 9 | 16 | 9 | 6 | 21 | 17 | 4 | 2 | -| 7 | 11 | 17 | 10 | 9 | 4 | 25 | 11 | 0 | 8 | -| 19 | 5 | 5 | 22 | 9 | 4 | 19 | 17 | 6 | 2 | -| 7 | 11 | 17 | 4 | 9 | 10 | 25 | 17 | 0 | 2 | -| 23 | 3 | 1 | 30 | 9 | 0 | 17 | 15 | 8 | 4 | -| 11 | 9 | 13 | 12 | 9 | 6 | 23 | 15 | 2 | 4 | -| 11 | 9 | 13 | 18 | 9 | 0 | 23 | 9 | 2 | 10 | -| 15 | 7 | 9 | 18 | 9 | 4 | 21 | 15 | 4 | 4 | -| 19 | 5 | 5 | 24 | 9 | 2 | 19 | 15 | 6 | 4 | -| 7 | 11 | 17 | 6 | 9 | 8 | 25 | 15 | 0 | 4 | -| 7 | 11 | 17 | 12 | 9 | 2 | 25 | 9 | 0 | 10 | -| 11 | 9 | 13 | 14 | 9 | 4 | 23 | 13 | 2 | 6 | -| 23 | 3 | 1 | 26 | 9 | 4 | 17 | 19 | 8 | 0 | -| 11 | 9 | 13 | 8 | 9 | 10 | 23 | 19 | 2 | 0 | -| 15 | 7 | 9 | 20 | 9 | 2 | 21 | 13 | 4 | 6 | -| 15 | 7 | 9 | 14 | 9 | 8 | 21 | 19 | 4 | 0 | -| 7 | 11 | 17 | 14 | 9 | 0 | 25 | 7 | 0 | 12 | -| 19 | 5 | 5 | 26 | 9 | 0 | 19 | 13 | 6 | 6 | -| 7 | 11 | 17 | 8 | 9 | 6 | 25 | 13 | 0 | 6 | -| 19 | 5 | 5 | 20 | 9 | 6 | 19 | 19 | 6 | 0 | -| 7 | 11 | 17 | 2 | 9 | 12 | 25 | 19 | 0 | 0 | +#+begin_src emacs-lisp + (setq rainbow (-annotate (lambda (n) (--map (mod n it) '(2 3 5 7))) (-iota (* 2 3 5 7)))) + + + (defun process-machine (machine) + (let* ((matrix (-distinct (matrix-buttons (fix-machine machine)))) + (solmod (--map (solve-well-ordered-chunks-mod matrix it) '(2 3 5 7))) + (solns nil) + (numcand (apply '* (-map 'length solmod))) + (count 0)) + ;; Oh Programming Gods, have mercy of me for I have sinned + (-each (car solmod) + (lambda (a) + (-each (cadr solmod) + (lambda (b) + (-each (caddr solmod) + (lambda (c) + (-each (cadddr solmod) + (lambda (d) + (let ((cand (--map (cdr (assoc it rainbow)) (-zip-lists a b c d)))) + (message (format "machine %d. Verifying %d / %d - found %d" machine-id (setq count (1+ count)) numcand (length solns))) + (when (test-soln matrix cand) (push cand solns))))))))))) + ; (-min (-map '-sum + solns + ; )) + ) + + ) + (setq machine-id -1) + (-sum (--map (progn + (setq machine-id (1+ machine-id)) + (-min (-map '-sum (process-machine it)))) machines) ) +#+end_src +#+RESULTS: +: 33 +#+RESULTS: +(process-machine (nth 51 machines)) This is it. It will take forever.