Langton's ant
One ant, two colours, two rules. For 10,000 steps it makes a mess; then, for no visible reason, it starts building a road and never stops.
Chris Langton, 1986 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Chris Langton invented the ant in 1986. It is a tiny machine walking on a grid of white and black squares. It is a cousin of the cellular automata: the rule is local, but only the cell under the ant changes. Such machines are also called turmites (Turing machine plus termite).
Read the story
There is no program text. What plays the role of the program is the starting grid; the usual start is all white.
What makes the ant famous is its history. From an empty grid it first makes small, often symmetric shapes, then about ten thousand steps of what looks like noise, and then, at step 9,977, it falls into a 104-step cycle that builds a diagonal highway out to infinity. Nobody has a short explanation why. Whether the ant always ends up on a highway from any finite starting pattern is still an open question. It has been proved that its path is always unbounded.
The machine
| The ant stands on | It does |
|---|---|
| A white square | Turn 90° right, flip the square to black, step forward |
| A black square | Turn 90° left, flip the square to white, step forward |
That is all. The ant can compute: Gajardo, Moreira and Goles (2002) showed that the ant's path can evaluate any Boolean circuit, given the right starting grid.
Generalisations give each colour its own turn. The original is "RL"; "RLR", "LLRR" and others grow symmetric shapes, spirals or chaos.
Example
The script finds the start of the highway itself, by looking for the first step after which the ant sees…
11000 steps, 834 black cells, highway (period 104) from about step 9977
The script finds the start of the highway itself, by looking for the first step after which the ant sees the same colours every 104 steps. Below is the lower-left corner of the picture, with the highway leaving the chaos towards the bottom left (@ is the ant):
............###...#..##.
...........#..###..#.#..
..........###...#..##...
.........#..###..#.#...#
........###...#..##...#.
.......#..###..#.#...#..
......###...#..##....#..
.....#..###..#.#.....#..
....###...#..##......#.#
...#..###..#.#........##
..###...#..##..........#
.#..###..#.#............
#####.#..##.............
###..#.#.#..............
.#...#.##...............
.#..##.#................
#...###.................
#.#@.#..................
Run shib run langtons-ant -e 400 for the early, symmetric phase, and 9000 for the chaos just before the road starts.
Patterns it teaches
- Cellular automata: a mobile one. The state is the grid plus the ant's position and direction.
- Turing completeness: computation from a rule you can say in one breath, if you get to design the starting grid.
Try this
- Start the ant on a grid with one black square somewhere near it (edit the script). Does it still build a highway? After how many steps?
- Make the turns depend on three colours, "RLR". Does it ever build a highway?
- Hard: change the period test to find the smallest period automatically.
Further
- Wikipedia: Langton's ant
- Chris Langton, "Studying artificial life with cellular automata", Physica D 22 (1986).
- Gajardo, Moreira and Goles, "Complexity of Langton's ant", Discrete Applied Mathematics (2002).
See also
Cellular automata
Reversible computing
Write your own in Run Convert a program from Langton's ant
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: langtons-ant.
Command line
shib run langtons-ant -e '8'shib manual langtons-antSource
- Module
langs/museum/ports.js- Interpreter
langs/museum/langtons-ant.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org