aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2023/day08
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2023/day08')
-rw-r--r--AoC2023/day08/solver.lisp24
1 files changed, 9 insertions, 15 deletions
diff --git a/AoC2023/day08/solver.lisp b/AoC2023/day08/solver.lisp
index 0681e15..76001f1 100644
--- a/AoC2023/day08/solver.lisp
+++ b/AoC2023/day08/solver.lisp
@@ -18,21 +18,15 @@ ZZZ = (ZZZ, ZZZ)")
(values instructions graph))))
(defun traverse (instructions graph location terminatep)
- (labels ((rec (steps)
- (if (funcall terminatep location)
- (values steps location)
- (rec (+ steps (steps-needed)))))
- (steps-needed ()
- (loop
- for direction across instructions
- do (arrows:-<>
- (ecase direction
- (#\L #'first)
- (#\R #'second))
- (funcall <> (gethash location graph))
- (setf location <>))
- count direction until (funcall terminatep location))))
- (rec 0)))
+ (loop
+ for i from 0
+ do (arrows:-<>
+ (ecase (aref instructions (mod i (length instructions)))
+ (#\L #'first)
+ (#\R #'second))
+ (funcall <> (gethash location graph))
+ (setf location <>))
+ count i until (funcall terminatep location)))
(defun solver1 (lines)
(multiple-value-bind (instructions graph)