diff --git a/rover.fnl b/rover.fnl index 1ebf97c..e25cc45 100644 --- a/rover.fnl +++ b/rover.fnl @@ -13,22 +13,23 @@ :actual actual# }))))) -(fn rotate [direction rotation] - (let [chooser - (match rotation - :r { - :n :e - :e :s - :s :w - :w :n - } - :l { - :n :w - :w :s - :s :e - :e :n - })] - (. chooser direction))) +(fn turn-left [direction] + (-> { + :n :w + :w :s + :s :e + :e :n + } + (. direction))) + +(fn turn-right [direction] + (-> { + :n :e + :e :s + :s :w + :w :n + } + (. direction))) (fn command [rover string] @@ -38,8 +39,8 @@ :s (merge rover {:y (- rover.y 1)}) :w (merge rover {:x (- rover.x 1)}) :e (merge rover {:x (+ rover.x 1)})) - :r (merge rover {:direction (rotate rover.direction :r)}) - :l (merge rover {:direction (rotate rover.direction :l)}) + :r (merge rover {:direction (turn-right rover.direction)}) + :l (merge rover {:direction (turn-left rover.direction)}) _ (assert false (. "unrecognised command " string)))) (fn execute [rover [cmd & cmds]]