From e746bb514ed11a8ecb75141a3ec444ad9648544c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 22 Jan 2023 18:06:41 +0000 Subject: [PATCH] now it can turn left as well as right --- rover.fnl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rover.fnl b/rover.fnl index fdff0ec..1ebf97c 100644 --- a/rover.fnl +++ b/rover.fnl @@ -22,7 +22,12 @@ :s :w :w :n } - )] + :l { + :n :w + :w :s + :s :e + :e :n + })] (. chooser direction))) @@ -34,6 +39,7 @@ :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)}) _ (assert false (. "unrecognised command " string)))) (fn execute [rover [cmd & cmds]] @@ -85,6 +91,10 @@ (expect "Rotates to south when pointing east and asked to turn right" (r:execute [:r]) {:x 2 :y 4 :direction :s})) +(let [r (rover 2 4 :s)] + (expect "Rotates to east when pointing south and asked to turn left" + (r:execute [:l]) {:x 2 :y 4 :direction :e})) + (let [r (rover 2 4 :w)] (expect "Rotates to north when pointing west and asked to turn right" (r:execute [:r]) {:x 2 :y 4 :direction :n}))