Langton's ant: Difference between revisions

Content added Content deleted
Line 1,665: Line 1,665:
[[File:LangtonsAnt.png|right|thumb|Output]]
[[File:LangtonsAnt.png|right|thumb|Output]]


<lang mathematica>position = {50, 50};
<lang mathematica>direction = 1;
data = SparseArray[{{50, 50} -> -1}, {100, 100}, 1];
direction = 1;
NestWhile[
data = SparseArray[{position -> -1}, {100, 100}, 1];
{Re@#, Im@#} &@(direction *= (data[[Sequence @@ #]] *= -1) I) + # &,
While[1 <= Min@position <= Max@position <= 100,
{50, 50}, 1 <= Min@# <= Max@# <= 100 &];
position += {Re@#,
Image@data</lang>
Im@#} &@(direction *= (data[[Sequence @@ position]] *= -1) I)];
Image[data]</lang>


=={{header|OCaml}}==
=={{header|OCaml}}==