Langton's ant: Difference between revisions

Content added Content deleted
(implementation AutoIt solution)
Line 3,198: Line 3,198:
print "\n".join("".join(row) for row in M)</lang>
print "\n".join("".join(row) for row in M)</lang>
The output is the same as the basic D version.
The output is the same as the basic D version.

=={{header|R}}==
<lang R>
langton.ant = function(n = 100) {
map = matrix(data = 0, nrow = n, ncol = n)
p = floor(c(n/2, n/2))
d = sample(1:4, 1)
i = 1
while(p[1] > 0 & p[1] <= n & p[2] > 0 & p[2] <= n) {
if(map[p[1], p[2]] == 1) {
map[p[1], p[2]] = 0
p = p + switch(d, c(0, 1), c(-1, 0), c(0, -1), c(1, 0))
d = ifelse(d == 4, 1, d + 1)
} else {
map[p[1], p[2]] = 1
p = p + switch(d, c(0, -1), c(1, 0), c(0, 1), c(-1, 0))
d = ifelse(d == 1, 4, d - 1)
}
}
return(map)
}

image(langton.ant(), xaxt = "n", yaxt = "n", bty = "n")
</lang>


=={{header|Racket}}==
=={{header|Racket}}==