Langton's ant: Difference between revisions

Content added Content deleted
(→‎LOLCODE: Add implementation)
(→‎Clojure: Add implementation)
Line 530: Line 530:
##
##
</pre>
</pre>

=={{header|Clojure}}==
In keeping with the spirit of Clojure, this program eschews mutable state entirely. Instead, all computation occurs within a single recursive loop whose "variables" are "adjusted" at each iteration, a natural fit for this particular execution model.
<lang Clojure>(let [bounds (set (range 100))
xs [1 0 -1 0] ys [0 -1 0 1]]
(loop [dir 0 x 50 y 50
grid {[x y] false}]
(if (and (bounds x) (bounds y))
(let [cur (not (grid [x y]))
dir (mod (+ dir (if cur -1 1)) 4)]
(recur dir (+ x (xs dir)) (+ y (ys dir))
(merge grid {[x y] cur})))
(doseq [col (range 100)]
(println
(apply str
(map #(if (grid [% col]) \# \.)
(range 100))))))))</lang>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==