-
-
Save Sose/b07f44536f3e97fd1307b1edfa8b5840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn turtle-repeat! [[times {:keys [:instructions :index]}]] | |
(doseq [x (range times)] | |
(do-script! instructions (count instructions)))) | |
(defn do-script! [script until-step] | |
(doseq [step-n (range until-step)] | |
(let [[instr & data] (nth script step-n)] | |
(case instr | |
:move (move-turtle! (first data) step-n) | |
:turn-right (turn-right! (first data)) | |
:turn-left (turn-left! (first data)) | |
:repeat (turtle-repeat! data) | |
:pen nil)))) ;; pen instructions are handled by (pen-down? step-n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment