aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2023
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-12-08 13:45:14 +0100
committerOscar Najera <hi@oscarnajera.com>2023-12-08 13:45:14 +0100
commit5f0101dd3c9859bacc397dc62e9ec29e20ebebe0 (patch)
tree6ea98943b6df35d59dc2b98a17f97c64b32d353d /AoC2023
parent3c0c1cda01df991760a90a1f1893b903534b0fb7 (diff)
downloadscratch-5f0101dd3c9859bacc397dc62e9ec29e20ebebe0.tar.gz
scratch-5f0101dd3c9859bacc397dc62e9ec29e20ebebe0.tar.bz2
scratch-5f0101dd3c9859bacc397dc62e9ec29e20ebebe0.zip
refactor
Diffstat (limited to 'AoC2023')
-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)