Anonymous user
Langton's ant: Difference between revisions
Simpler D version
(→{{header|C Sharp|C#}}: Output was double spaced - fixed and eliminated blank lines at top of output.) |
(Simpler D version) |
||
Line 391:
=={{header|D}}==
A basic textual version.
<lang
enum Direction { up, right, down, left }
enum Color : char { white = '.', black = '#' }
Line 400 ⟶ 399:
enum width = 75, height = 52;
enum nsteps = 12_000;
auto M = new Color[][](height, width);
▲ int y = height / 2;
auto dir = Direction.up;
for (int i = 0; i < nsteps && x < width && y < height; i++) {
immutable turn = M[y][x] == Color.black;
M[y][x] = (M[y][x] == Color.black) ? Color.white : Color.black;
final switch(dir) {
case Direction.up: y--; break;
case Direction.right: x
case Direction.down: y++; break;
case Direction.left: x
}
}
▲ writeln(cast(char[])row);
}</lang>
Output:
Line 477 ⟶ 470:
...........................................................................
...........................................................................</pre>
=={{header|Go}}==
[[file:GoAnt.png|right|thumb|Output png]]
|