diff --git a/rover.fnl b/rover.fnl index 0def724..045852c 100644 --- a/rover.fnl +++ b/rover.fnl @@ -6,17 +6,21 @@ ,expected true _# false) (assert false (view { - :text ,text - :expected ,expected - :actual actual# - }))))) + :text ,text + :expected ,expected + :actual actual# + }))))) -(fn command [rover commands] - (match rover.direction - :n {:x rover.x :y (+ rover.y 1) :direction :n} - :s {:x rover.x :y (- rover.y 1) :direction :s} - :w {:x (- rover.x 1) :y rover.y :direction :w} - :e {:x (+ rover.x 1) :y rover.y :direction :e})) +(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})] + (if (next cmds) + (r1:command cmds) + r1))) (fn rover [x y direction] {: x @@ -52,4 +56,10 @@ (expect "Moves east when pointing east and asked to move forward" (r:command [:f]) {:x 1 :y 0 :direction :e})) +(let [r (rover 1 1 :s)] + (expect "The rover acts on multiple commands" + (r:command [:f :f :f]) + {:x 1 :y -2 :direction :s})) + + (print "OK")