Langton's ant: Difference between revisions

Updated first D entry
(Add Seed7 example)
(Updated first D entry)
Line 1,296:
=={{header|D}}==
===Textual Version===
<lang d>void main() @safe {
import std.stdio, std.traits;
 
enum width = 75, height = 52;
enum maxSteps = 12_000;
enum Direction { up, right, down, left }
enum Color : char { white = '.', black = '#' }
uint x = width / 2, y = height / 2;
auto M = new Color[][](height, width);
auto dir = Direction.up;
 
with (Color)
for (int i = 0; i < maxSteps && x < width && y < height; i++) {
immutable turn = M[y][x] == black;
dir = [EnumMembers!Direction][(dir + (turn ? 1 : -1)) & 3];
M[y][x] = (M[y][x] == black) ? white : black;
final switch(dir) with (Direction) {
case up: y--; break;
case right: x--; break;
case down: y++; break;
case left: x++; break;
}
}
 
writefln("%(%-(%c%)\n%)", M);
}</lang>
{{out}}