aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-01-13 12:31:16 +0100
committerOscar Najera <hi@oscarnajera.com>2023-01-13 12:31:16 +0100
commit25957c30efdefce0c349a9ddf9100a458fa3e6ab (patch)
tree936c4ad3805353162ca0ae0f8ee3aada1e6eae99 /AoC2022
parenta572f1303d939075e87756a0143254186e1fb879 (diff)
downloadscratch-25957c30efdefce0c349a9ddf9100a458fa3e6ab.tar.gz
scratch-25957c30efdefce0c349a9ddf9100a458fa3e6ab.tar.bz2
scratch-25957c30efdefce0c349a9ddf9100a458fa3e6ab.zip
Day 20 part2
Diffstat (limited to 'AoC2022')
-rw-r--r--AoC2022/20/solver.lisp25
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))))))