diff options
Diffstat (limited to 'AoC2022/20/solver.lisp')
-rw-r--r-- | AoC2022/20/solver.lisp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/AoC2022/20/solver.lisp b/AoC2022/20/solver.lisp index f341a43..dc1f2c7 100644 --- a/AoC2022/20/solver.lisp +++ b/AoC2022/20/solver.lisp @@ -38,12 +38,12 @@ ((move! reverse forward element-idx (abs shift)))) (values forward reverse)) -(defun shuffle-pointers (msg) +(defun shuffle-pointers (msg repeat) (multiple-value-bind (forward reverse) (directional-pointers (length msg)) - (dotimes (element-idx (length msg)) - ;; (format t "st: ~a f: ~a r: ~a~%" (ordered-series msg forward) forward reverse) - (shuffle! forward reverse element-idx (svref msg element-idx))) - ;; (format t "st: ~a f: ~a r: ~a~%" (ordered-series msg forward) forward reverse) + (dotimes (_ repeat) + (dotimes (element-idx (length msg)) + ;; (format t "st: ~a f: ~a r: ~a~%" (ordered-series msg forward) forward reverse) + (shuffle! forward reverse element-idx (svref msg element-idx)))) (values forward reverse))) (defun ordered-series (msg forward) @@ -55,16 +55,21 @@ (setf (svref series count) (svref msg i))))) -(defun solver (message) +(defun solver (repeat message) (let ((new-array - (ordered-series message (shuffle-pointers message)))) + (ordered-series message (shuffle-pointers message repeat)))) (+ (svref new-array (mod 1000 (length new-array))) (svref new-array (mod 2000 (length new-array))) (svref new-array (mod 3000 (length new-array)))))) +(defun times-decrypt-key (msg) + (map 'vector (lambda (x) (* 811589153 x)) msg)) + (fiveam:test solutions - (fiveam:is (= 3 (solver *msg*))) - (fiveam:is (= 7225 (solver - (map 'vector #'parse-integer (uiop:read-file-lines "input")))))) + (fiveam:is (= 3 (solver 1 *msg*))) + (fiveam:is (= 1623178306 (solver 10 (times-decrypt-key *msg*)))) + (let ((input-msg (map 'vector #'parse-integer (uiop:read-file-lines "input")))) + (fiveam:is (= 7225 (solver 1 input-msg))) + (fiveam:is (= 548634267428 (solver 10 (times-decrypt-key input-msg)))))) |