Langton's ant: Difference between revisions

Removed one cast from D version
(Fixed D comments)
(Removed one cast from D version)
Line 87:
=={{header|D}}==
A basic textual version.
<lang D>import std.stdio, std.algorithm, std.traits;
 
enum Direction { up, right, down, left }
Line 94:
 
void main() {
enum width = 75, height = 52;
enum nsteps = 12_000;
 
auto M = new Color[][](height, width);
int x = width / 2;
int y = height / 2;
Directionauto dir = Direction.up;
 
for (int i = 0; i < nsteps &&
x >= 0 && y >= 0 && x < width && y < height; i++) {
Turnimmutable turn = M[y][x] == Color.black ? Turn.left : Turn.right;
M[y][x] = M[y][x] == Color.black ? Color.white : Color.black;
 
immutable dird = cast(Direction)((4 + dir + (turn == Turn.right ? +1 : -1)) % 4);
dir = [EnumMembers!Direction][d];
final switch(dir) {
case Direction.up: y--; break;
case Direction.rightup: x y--; break;
case Direction.downright: y++x--; break;
case Direction.leftdown: xy++; break;
case Direction.left: } x++; break;
}
}
 
foreach (row; M)
writeln(cast(char[])row);
}</lang>
Output:
Anonymous user