Langton’s Ant — it is a four-dimensional universal Turing machine with four states. It was invented by Chris Langton in 1986. It is basically an ant sitting on a square lattice of cages that are initially white in color. The ant moves along the plane and changes the color of the cells, creating patterns on it. But the movement of the ant is not accidental; follows the following set of rules:
- If an ant is on a black square, it turns right 90 degrees and moves forward one unit.
- If an ant is on a white square, it rotates left 90 degrees and moves forward one unit.
- When the ant leaves the square, it inverts the color.
As the ant begins, it creates a black and white pattern in time of movement. Initially, the changes are not distinctive, but as we repeat this over and over, a beautiful pattern emerges. But if we increase the number of iterations even more (say ~ 10,000), the ant starts repeating its path with a gradual shift instead of creating new patterns. This gives us an infinite highway-like model. The ant continues along this highway and displays the following diagram.

See a visual explanation of Langton’s ant from here . This helps to visualize exactly how the ant works.
The Python-3 code for Langton’s ant is below:
|
Output:

White cells are indicated as "" (space) and black cells are — like “(dot).