rover

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

commit 67bfda490ee6315321d36a60e5463c42ca988497
parent 574c98236864f2b1e9c433ef88a342739d95bd85
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 22 Jan 2023 18:19:04 +0000

rewrite execute usiung accumulate, add second test case

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

diff --git a/rover.fnl b/rover.fnl @@ -43,11 +43,10 @@ :l {:direction (turn-left rover.direction)} _ (assert false (. "unrecognised command " string))))) -(fn execute [rover [cmd & cmds]] - (let [r1 (command rover cmd)] - (if (next cmds) - (execute r1 cmds) - r1))) +(fn execute [rover cmds] + (accumulate [rover rover + _ c (ipairs cmds)] + (merge rover (command rover c)))) (fn rover [x y direction] {: x @@ -99,5 +98,10 @@ (expect "Rotates to north when pointing west and asked to turn right" (execute r [:r]) {:x 2 :y 4 :direction :n})) +(let [r (rover 1 1 :s)] + (expect "Multiple commands are executed in the right order" + (execute r [:l :l :f :f :f :r :f]) + {:x 2 :y 4 :direction :e})) + (print "OK")