rover

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 94325e53a04bb31d1d8b922d7d66ced4e1109849
parent e746bb514ed11a8ecb75141a3ec444ad9648544c
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 22 Jan 2023 18:09:39 +0000

separate turn-left and turn-right functions

Diffstat:
Mrover.fnl | 37+++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)

diff --git 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]]