reduce repetition

main
Daniel Barlow 2023-01-22 17:50:48 +00:00
parent c02c0aabca
commit 1ba4399221
1 changed files with 5 additions and 4 deletions

View File

@ -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)))