commit 1ba4399221298da50cb4269921242cf7cab06116 parent c02c0aabcad89f0a525e20bdc024447a7de907c3 Author: Daniel Barlow <dan@telent.net> Date: Sun, 22 Jan 2023 17:50:48 +0000 reduce repetition Diffstat:
| M | rover.fnl | | | 9 | +++++---- |
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/rover.fnl b/rover.fnl @@ -1,4 +1,5 @@ (local { : view } (require :fennel)) +(local { : merge } (require :lume)) (macro expect [text actual expected] `(let [actual# ,actual] @@ -14,10 +15,10 @@ (fn command [rover [cmd & cmds]] (let [r1 (match rover.direction - :n {:x rover.x :y (+ rover.y 1) :direction :n : command} - :s {:x rover.x :y (- rover.y 1) :direction :s : command} - :w {:x (- rover.x 1) :y rover.y :direction :w : command} - :e {:x (+ rover.x 1) :y rover.y :direction :e : command})] + :n (merge rover {:y (+ rover.y 1)}) + :s (merge rover {:y (- rover.y 1)}) + :w (merge rover {:x (- rover.x 1)}) + :e (merge rover {:x (+ rover.x 1)}))] (if (next cmds) (r1:command cmds) r1)))