reduce repetition
This commit is contained in:
parent
c02c0aabca
commit
1ba4399221
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user