From 6546a16ec67aa137144ddd0d3a0ad9830c15077a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 22 Jan 2023 17:21:34 +0000 Subject: [PATCH] move forward east and west --- rover.fnl | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/rover.fnl b/rover.fnl index 0d6da5b..dd77165 100644 --- a/rover.fnl +++ b/rover.fnl @@ -14,7 +14,9 @@ (fn command [rover commands] (match rover.direction :n {:x 0 :y (+ rover.y 1) :direction :n} - :s {:x 0 :y (- rover.y 1) :direction :s})) + :s {:x 0 :y (- rover.y 1) :direction :s} + :w {:x (- rover.x 1) :y 0 :direction :w} + :e {:x (+ rover.x 1) :y 0 :direction :e})) (fn rover [x y direction] {: x @@ -35,16 +37,19 @@ {})) (let [r (rover 0 0 :n)] - (expect - "Moves north when pointing north and asked to move forward" - (r:command [:f]) - {:x 0 :y 1 :direction :n})) + (expect "Moves north when pointing north and asked to move forward" + (r:command [:f]) {:x 0 :y 1 :direction :n})) (let [r (rover 0 0 :s)] - (expect - "Moves south when pointing south and asked to move forward" - (r:command [:f]) - {:x 0 :y -1 :direction :s})) + (expect "Moves south when pointing south and asked to move forward" + (r:command [:f]) {:x 0 :y -1 :direction :s})) +(let [r (rover 0 0 :w)] + (expect "Moves west when pointing west and asked to move forward" + (r:command [:f]) {:x -1 :y 0 :direction :w})) + +(let [r (rover 0 0 :e)] + (expect "Moves east when pointing east and asked to move forward" + (r:command [:f]) {:x 1 :y 0 :direction :e})) (print "OK")