How to resolve the algorithm Langton's ant step by step in the Aime programming language
How to resolve the algorithm Langton's ant step by step in the Aime programming language
Table of Contents
Problem Statement
Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
This rather simple ruleset leads to an initially chaotic movement pattern, and after about 10000 steps, a cycle appears where the ant moves steadily away from the starting location in a diagonal corridor about 10 cells wide.
Conceptually the ant can then walk infinitely far away.
Start the ant near the center of a 100x100 field of cells, which is about big enough to contain the initial chaotic part of the movement. Follow the movement rules for the ant, terminate when it moves out of the region, and show the cell colors it leaves behind.
The problem has received some analysis; for more details, please take a look at the Wikipedia article (a link is below)..
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Langton's ant step by step in the Aime programming language
Source code in the aime programming language
void
ant(integer x, y, d, list map)
{
while (-1 < x && x < 100 && -1 < y && y < 100) {
integer e, p, w;
data b;
b = map[y];
w = b[x >> 3];
p = 1 << (7 - (x & 7));
b[x >> 3] = w ^ p;
d += w & p ? 1 : 3;
e = d & 1;
set(e, $e + ((d & 2) - 1) * (2 * e - 1));
}
}
integer
main(void)
{
file f;
list l;
call_n(100, lb_p_data, l, data().run(13, 0));
ant(50, 50, 2, l);
f.create("ant.pbm", 00644).text("P4\n100 100\n");
l.ucall(f_data, 1, f);
0;
}
You may also check:How to resolve the algorithm Haversine formula step by step in the F# programming language
You may also check:How to resolve the algorithm Erdős-Nicolas numbers step by step in the Delphi programming language
You may also check:How to resolve the algorithm Comments step by step in the XQuery programming language
You may also check:How to resolve the algorithm Singleton step by step in the Perl programming language
You may also check:How to resolve the algorithm Catamorphism step by step in the J programming language