rover

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

commit 6546a16ec67aa137144ddd0d3a0ad9830c15077a
parent 89945064d54fdb4af36b3b351b56bffbd3540ee3
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 22 Jan 2023 17:21:34 +0000

move forward east and west

Diffstat:
Mrover.fnl | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git 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")