bmat ← ##.life bmat ⍝ John Conway's "Game of Life".
This version of John Conway's cellular automaton takes a boolean matrix argument
representing a population of "creatures" and returns a boolean matrix of the
succeeding generation. Each cell in the matrix may be occupied by a creature
(1) or be empty (0).
The two rules of life are:
[1] An empty cell that has exactly 3 neighbouring occupied cells is "born" into
in the next generation.
[2] An occupied cell that has exactly 2 or 3 neighbouring occupied cells, sur-
vives to the next generation. Otherwise, its occupant dies (of loneliness or
overcrowding).
┼───┼───┼───┼
│ · │ · │ · │
┼───┼───┼───┼
│ ⍟ │ ⍟ │ ⍟ │
┼───┼───┼───┼
│ · │ · │ · │
┼───┼───┼───┼
In the above example, only the creature in the centre survives but new ones are
born above and below it. The next generation thus has three creatures in a vert-
ical line; the generation after that reverts to the horizontal; and so on.
For more complex configurations, the sequence may develop for many generations
before repeating. An instance of an interesting initial configuration is the R-
Pentamino:
┼───┼───┼───┼
│ · │ ⍟ │ ⍟ │
┼───┼───┼───┼
│ ⍟ │ ⍟ │ · │
┼───┼───┼───┼
│ · │ ⍟ │ · │
┼───┼───┼───┼
In the coding in this workspace, the use of ⊖ and ⌽ render opposite edges of the
creatures' rectangular universe, adjacent. In effect, the creatures live on the
surface of a torus (doughnut, innertube, ..). We illustrate this arrangement
using a little square diagram, which shows the orientations of the connections
of corresponding edges:
torus
┌─→─┐ upper edge joined to lower,
⍋ ⍋ left edge joined to right.
└─→─┘
We can visualise the square, made from a very flexible material, being distorted
so that the left and right sides are joined with their ⍋ arrows aligned to form
a tube. We then stretch the tube and bend it to join its two circular ends with
the → arrows aligned, to form a torus.
We can investigate edge connections (universes, manifolds) other than the torus;
it is most convenient to explore these using auxiliary operators, leaving the
coding of the life function itself, unchanged.
For example, we might want the edges not to be joined at all; creatures crossing
the boundaries would just disappear.
┌───┐
│ │ plane: no edge connections.
└───┘
Easy-peasy! We just prefix a 0 row and column to the argument matrix and remove
a row and column from the result:
plane←{ ⍝ ┌───┐
1 0↓0 1↓⍺⍺ 0,0⍪⍵ ⍝ │ │
} ⍝ └───┘
To see the effect, let's make an initial configuration:
glider ← 3 3⍴0 0 1 1 0 1 0 1 1
and a function to display each generation:
show←{'·⍟'[⎕io+⍵]}
show glider
··⍟
⍟·⍟
·⍟⍟
We can see the glider's first few generations, using the power operator →pow←:
0 disp show¨(0 to 6) life pow¨ ⊂5 5↑glider
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│
│·····│·····│·····│·····│·····│·····│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Alternatively, operator →traj← applies its operand function repeatedly until a
cycle is detected:
0 disp show¨ life traj 5 5↑glider
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
To save typing, we can distil the above expression into a "try" operator:
try←{0 disp show¨ ⍺⍺ traj ⍵} ⍝ repeat until cycle detected.
life try 5 5↑glider ⍝ life on a torus.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Now, spot the difference if we apply life under our plane operator. As soon as
the glider hits the edge, parts of it disappear and so it no longer flies:
life plane try 5 5↑glider ⍝ life on a plane.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│····⍟│···⍟⍟│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│···⍟⍟│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Note that the final ⍟⍟ is a stable configuration, as each cell has exactly 3
neighbours. ⍟⍟
Other possibilities
-------------------
We could connect just two of the edges to see life on a cylinder:
cylinder←{ ⍝ ┌───┐
1 0↓⍺⍺ 0⍪⍵ ⍝ ⍋ ⍋
} ⍝ └───┘
life cylinder try 5 5↑glider ⍝ life on a cylinder.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│⍟···⍟│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟···⍟│⍟···⍟│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
For completeness, we should have a null operator for life on a torus:
torus←{ ⍝ ┌─→─┐
⍺⍺ ⍵ ⍝ ⍋ ⍋
} ⍝ └─→─┘
life torus try 5 5↑glider ⍝ life on a torus.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Finally, we could connect opposite edges with a twist to give two further uni-
verses: möbius and klein. To produce the effect of a twist prior to connecting
opposite edges, we append the reverse of each of the outside columns to their
opposing side. After applying the operand function, we must remember to remove
these extra columns.
⍝ append reversed columns.
twist←{ ⍝ ┌───┐ ┌ ┌───┐ ┐
¯1⌽⍵,⌽⊖2↑[1+⎕io]¯1⌽⍵ ⍝ ⍋ ↑ → ↓,⍋ ↑,⍒
} ⍝ └───┘ └ └───┘ ┘
Then:
plane←{ ⍝ ┌───┐
1 0↓0 1↓⍺⍺ 0,0⍪⍵ ⍝ │ │
} ⍝ └───┘
cylinder←{ ⍝ ┌───┐
1 0↓⍺⍺ 0⍪⍵ ⍝ ⍋ ⍋
} ⍝ └───┘
torus←{ ⍝ ┌─→─┐
⍺⍺ ⍵ ⍝ ⍋ ⍋
} ⍝ └─→─┘
möbius←{ ⍝ ┌───┐ möbius strip
1 0↓0 2↓¯1⌽⍺⍺ 0⍪twist ⍵ ⍝ ⍋ ⍒
} ⍝ └───┘
klein←{⎕ml←0 ⍝ ┌─→─┐ klein bottle
0 2↓¯1⌽⍺⍺ twist ⍵ ⍝ ⍋ ⍒
} ⍝ └─→─┘
life möbius try 5 5↑glider ⍝ life on a möbius strip.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟····│⍟····│⍟····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│⍟····│⍟····│⍟····│⍟····│⍟····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│·····│···⍟·│·····│····⍟│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│····⍟│····⍟│····⍟│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
life klein try 5 5↑glider ⍝ life on a klein bottle.
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟···⍟│⍟···⍟│⍟⍟··⍟│·⍟··⍟│·⍟···│·⍟··⍟│⍟····│·⍟···│·····│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│····⍟│⍟··⍟·│⍟····│⍟⍟···│⍟⍟··⍟│·⍟···│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│⍟····│⍟····│⍟····│⍟····│·····│⍟····│·····│·····│·····│·····│·····│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│·····│···⍟·│·····│····⍟│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│·····│···⍟·│·····│····⍟│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│⍟····│⍟····│⍟····│⍟····│·····│⍟····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│····⍟│⍟··⍟·│⍟····│⍟⍟···│⍟⍟··⍟│·⍟···│·⍟⍟··│··⍟··│⍟·⍟··│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟···⍟│⍟···⍟│⍟⍟··⍟│·⍟··⍟│·⍟···│·⍟··⍟│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Library
-------
If you are viewing this page from an APL session, you can generate a boolean
matrix argument for life from any of the following patterns using the following
steps:
1. While pressing the _right_ mouse button, select the area within a box.
2. From this edit window menu, select Edit->Copy.
3. Open a new edit window to receive the character matrix: )ed -pattern
4. Select Edit->Paste in the new window, then close it.
5. Test using, for example: {⎕←'─'⍪'·⍟'[⎕io+⍵] ⋄ ∇ life ⍵} 20 50↑pattern='⍟'
R-Pentamino Glider Glider Gun (Gosper)
┌───┐ ┌───┐ ┌────────────────────────────────────┐
│·⍟⍟│ │··⍟│ │························⍟···········│
│⍟⍟·│ │⍟·⍟│ │······················⍟·⍟···········│
│·⍟·│ │·⍟⍟│ │············⍟⍟······⍟⍟············⍟⍟│
└───┘ └───┘ │···········⍟···⍟····⍟⍟············⍟⍟│
│⍟⍟········⍟·····⍟···⍟⍟··············│
Bistable states │⍟⍟········⍟···⍟·⍟⍟····⍟·⍟···········│
┌───┐ ┌────┐ │··········⍟·····⍟·······⍟···········│
│⍟⍟⍟│ │·⍟⍟⍟│ │···········⍟···⍟····················│
└───┘ │⍟⍟⍟·│ │············⍟⍟······················│
└────┘ └────────────────────────────────────┘
Stable states The glider gun generates a stream of
┌──┐ ┌────┐ gliders.
│⍟⍟│ │·⍟⍟·│
│⍟⍟│ │⍟··⍟│
└──┘ │·⍟⍟·│
└────┘
Ref: http://en.wikipedia.org/wiki/Conway's_Game_of_Life
Examples:
0 disp{'·⍟'[⎕io+⍵]}¨life traj 5 8↑3 3⍴0 0 1 1 0 1 0 1 1 ⍝ Glider.
┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
│··⍟·····│·⍟······│··⍟·····│········│········│········│········│········│········│········│········│····⍟···│····⍟⍟··│····⍟⍟··│····⍟⍟⍟·│·····⍟⍟·│····⍟·⍟·│······⍟⍟│·······⍟│·····⍟·⍟│·······⍟│······⍟·│·······⍟│········│········│········│········│········│········│········│········│·⍟······│·⍟⍟·····│·⍟⍟·····│·⍟⍟⍟····│··⍟⍟····│·⍟·⍟····│···⍟⍟···│····⍟···│··⍟·⍟···│····⍟···│···⍟····│····⍟···│········│········│········│········│········│········│········│········│······⍟·│······⍟⍟│······⍟⍟│⍟·····⍟⍟│⍟······⍟│⍟·····⍟·│⍟⍟······│·⍟······│·⍟·····⍟│·⍟······│⍟·······│·⍟······│········│········│········│········│········│········│········│········│···⍟····│···⍟⍟···│···⍟⍟···│···⍟⍟⍟··│····⍟⍟··│···⍟·⍟··│·····⍟⍟·│······⍟·│····⍟·⍟·│······⍟·│·····⍟··│······⍟·│········│········│········│········│········│········│········│········│⍟·······│⍟⍟······│⍟⍟······│⍟⍟⍟·····│·⍟⍟·····│⍟·⍟·····│··⍟⍟····│···⍟····│·⍟·⍟····│···⍟····│··⍟·····│···⍟····│········│········│········│········│········│········│········│········│·····⍟··│·····⍟⍟·│·····⍟⍟·│·····⍟⍟⍟│······⍟⍟│·····⍟·⍟│⍟······⍟│⍟·······│⍟·····⍟·│⍟·······│·······⍟│⍟·······│········│········│········│········│········│········│········│········│··⍟·····│··⍟⍟····│··⍟⍟····│··⍟⍟⍟···│···⍟⍟···│··⍟·⍟···│····⍟⍟··│·····⍟··│···⍟·⍟··│·····⍟··│····⍟···│·····⍟··│········│········│········│········│········│········│········│········│·······⍟│⍟······⍟│⍟······⍟│⍟⍟·····⍟│⍟⍟······│·⍟·····⍟│·⍟⍟·····│··⍟·····│⍟·⍟·····│
│⍟·⍟·····│··⍟⍟····│···⍟····│·⍟·⍟····│···⍟····│··⍟·····│···⍟····│········│········│········│········│········│········│········│········│·····⍟··│·····⍟⍟·│·····⍟⍟·│·····⍟⍟⍟│······⍟⍟│·····⍟·⍟│⍟······⍟│⍟·······│⍟·····⍟·│⍟·······│·······⍟│⍟·······│········│········│········│········│········│········│········│········│··⍟·····│··⍟⍟····│··⍟⍟····│··⍟⍟⍟···│···⍟⍟···│··⍟·⍟···│····⍟⍟··│·····⍟··│···⍟·⍟··│·····⍟··│····⍟···│·····⍟··│········│········│········│········│········│········│········│········│·······⍟│⍟······⍟│⍟······⍟│⍟⍟·····⍟│⍟⍟······│·⍟·····⍟│·⍟⍟·····│··⍟·····│⍟·⍟·····│··⍟·····│·⍟······│··⍟·····│········│········│········│········│········│········│········│········│····⍟···│····⍟⍟··│····⍟⍟··│····⍟⍟⍟·│·····⍟⍟·│····⍟·⍟·│······⍟⍟│·······⍟│·····⍟·⍟│·······⍟│······⍟·│·······⍟│········│········│········│········│········│········│········│········│·⍟······│·⍟⍟·····│·⍟⍟·····│·⍟⍟⍟····│··⍟⍟····│·⍟·⍟····│···⍟⍟···│····⍟···│··⍟·⍟···│····⍟···│···⍟····│····⍟···│········│········│········│········│········│········│········│········│······⍟·│······⍟⍟│······⍟⍟│⍟·····⍟⍟│⍟······⍟│⍟·····⍟·│⍟⍟······│·⍟······│·⍟·····⍟│·⍟······│⍟·······│·⍟······│········│········│········│········│········│········│········│········│···⍟····│···⍟⍟···│···⍟⍟···│···⍟⍟⍟··│····⍟⍟··│···⍟·⍟··│·····⍟⍟·│······⍟·│····⍟·⍟·│······⍟·│·····⍟··│······⍟·│········│········│········│········│········│········│········│········│⍟·······│⍟⍟······│⍟⍟······│⍟⍟⍟·····│·⍟⍟·····│
│·⍟⍟·····│·⍟⍟·····│·⍟⍟⍟····│··⍟⍟····│·⍟·⍟····│···⍟⍟···│····⍟···│··⍟·⍟···│····⍟···│···⍟····│····⍟···│········│········│········│········│········│········│········│········│······⍟·│······⍟⍟│······⍟⍟│⍟·····⍟⍟│⍟······⍟│⍟·····⍟·│⍟⍟······│·⍟······│·⍟·····⍟│·⍟······│⍟·······│·⍟······│········│········│········│········│········│········│········│········│···⍟····│···⍟⍟···│···⍟⍟···│···⍟⍟⍟··│····⍟⍟··│···⍟·⍟··│·····⍟⍟·│······⍟·│····⍟·⍟·│······⍟·│·····⍟··│······⍟·│········│········│········│········│········│········│········│········│⍟·······│⍟⍟······│⍟⍟······│⍟⍟⍟·····│·⍟⍟·····│⍟·⍟·····│··⍟⍟····│···⍟····│·⍟·⍟····│···⍟····│··⍟·····│···⍟····│········│········│········│········│········│········│········│········│·····⍟··│·····⍟⍟·│·····⍟⍟·│·····⍟⍟⍟│······⍟⍟│·····⍟·⍟│⍟······⍟│⍟·······│⍟·····⍟·│⍟·······│·······⍟│⍟·······│········│········│········│········│········│········│········│········│··⍟·····│··⍟⍟····│··⍟⍟····│··⍟⍟⍟···│···⍟⍟···│··⍟·⍟···│····⍟⍟··│·····⍟··│···⍟·⍟··│·····⍟··│····⍟···│·····⍟··│········│········│········│········│········│········│········│········│·······⍟│⍟······⍟│⍟······⍟│⍟⍟·····⍟│⍟⍟······│·⍟·····⍟│·⍟⍟·····│··⍟·····│⍟·⍟·····│··⍟·····│·⍟······│··⍟·····│········│········│········│········│········│········│········│········│····⍟···│····⍟⍟··│····⍟⍟··│····⍟⍟⍟·│·····⍟⍟·│····⍟·⍟·│······⍟⍟│·······⍟│·····⍟·⍟│·······⍟│······⍟·│·······⍟│········│········│········│········│········│········│········│········│·⍟······│
│········│········│········│··⍟·····│··⍟⍟····│··⍟⍟····│··⍟⍟⍟···│···⍟⍟···│··⍟·⍟···│····⍟⍟··│·····⍟··│···⍟·⍟··│·····⍟··│····⍟···│·····⍟··│········│········│········│········│········│········│········│········│·······⍟│⍟······⍟│⍟······⍟│⍟⍟·····⍟│⍟⍟······│·⍟·····⍟│·⍟⍟·····│··⍟·····│⍟·⍟·····│··⍟·····│·⍟······│··⍟·····│········│········│········│········│········│········│········│········│····⍟···│····⍟⍟··│····⍟⍟··│····⍟⍟⍟·│·····⍟⍟·│····⍟·⍟·│······⍟⍟│·······⍟│·····⍟·⍟│·······⍟│······⍟·│·······⍟│········│········│········│········│········│········│········│········│·⍟······│·⍟⍟·····│·⍟⍟·····│·⍟⍟⍟····│··⍟⍟····│·⍟·⍟····│···⍟⍟···│····⍟···│··⍟·⍟···│····⍟···│···⍟····│····⍟···│········│········│········│········│········│········│········│········│······⍟·│······⍟⍟│······⍟⍟│⍟·····⍟⍟│⍟······⍟│⍟·····⍟·│⍟⍟······│·⍟······│·⍟·····⍟│·⍟······│⍟·······│·⍟······│········│········│········│········│········│········│········│········│···⍟····│···⍟⍟···│···⍟⍟···│···⍟⍟⍟··│····⍟⍟··│···⍟·⍟··│·····⍟⍟·│······⍟·│····⍟·⍟·│······⍟·│·····⍟··│······⍟·│········│········│········│········│········│········│········│········│⍟·······│⍟⍟······│⍟⍟······│⍟⍟⍟·····│·⍟⍟·····│⍟·⍟·····│··⍟⍟····│···⍟····│·⍟·⍟····│···⍟····│··⍟·····│···⍟····│········│········│········│········│········│········│········│········│·····⍟··│·····⍟⍟·│·····⍟⍟·│·····⍟⍟⍟│······⍟⍟│·····⍟·⍟│⍟······⍟│⍟·······│⍟·····⍟·│⍟·······│·······⍟│⍟·······│········│········│········│········│········│
│········│········│········│········│········│········│········│···⍟····│···⍟⍟···│···⍟⍟···│···⍟⍟⍟··│····⍟⍟··│···⍟·⍟··│·····⍟⍟·│······⍟·│····⍟·⍟·│······⍟·│·····⍟··│······⍟·│········│········│········│········│········│········│········│········│⍟·······│⍟⍟······│⍟⍟······│⍟⍟⍟·····│·⍟⍟·····│⍟·⍟·····│··⍟⍟····│···⍟····│·⍟·⍟····│···⍟····│··⍟·····│···⍟····│········│········│········│········│········│········│········│········│·····⍟··│·····⍟⍟·│·····⍟⍟·│·····⍟⍟⍟│······⍟⍟│·····⍟·⍟│⍟······⍟│⍟·······│⍟·····⍟·│⍟·······│·······⍟│⍟·······│········│········│········│········│········│········│········│········│··⍟·····│··⍟⍟····│··⍟⍟····│··⍟⍟⍟···│···⍟⍟···│··⍟·⍟···│····⍟⍟··│·····⍟··│···⍟·⍟··│·····⍟··│····⍟···│·····⍟··│········│········│········│········│········│········│········│········│·······⍟│⍟······⍟│⍟······⍟│⍟⍟·····⍟│⍟⍟······│·⍟·····⍟│·⍟⍟·····│··⍟·····│⍟·⍟·····│··⍟·····│·⍟······│··⍟·····│········│········│········│········│········│········│········│········│····⍟···│····⍟⍟··│····⍟⍟··│····⍟⍟⍟·│·····⍟⍟·│····⍟·⍟·│······⍟⍟│·······⍟│·····⍟·⍟│·······⍟│······⍟·│·······⍟│········│········│········│········│········│········│········│········│·⍟······│·⍟⍟·····│·⍟⍟·····│·⍟⍟⍟····│··⍟⍟····│·⍟·⍟····│···⍟⍟···│····⍟···│··⍟·⍟···│····⍟···│···⍟····│····⍟···│········│········│········│········│········│········│········│········│······⍟·│······⍟⍟│······⍟⍟│⍟·····⍟⍟│⍟······⍟│⍟·····⍟·│⍟⍟······│·⍟······│·⍟·····⍟│·⍟······│⍟·······│·⍟······│········│
└────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┘
⍝ Conway's automaton is best viewed as an animation.
⍝ Here is a (pretty rough) gui front end:
gui←{⎕io←0 ⍝ Life animation.
show←{'·⍟'[⍵]} ⍝ formatting function.
f←⎕ns'' ⍝ localise class 9 name.
_←'f'⎕wc'form' ''(2 48)('OnTop' 1) ⍝ make a form.
_←'f.t'⎕wc'Text'(show ⍵)(0 0) ⍝ make a text box.
f.t.(FontObj BCol)←'Dyalog Std'(3/255) ⍝ font and white background.
⍺←500 ⍝ default 500ms delay.
⍺ ⍺⍺{ ⍝
_←⎕dl ⍺÷1000 ⍝ delay ⍺ ms.
next←⍺⍺ ⍵ ⍝ next generation.
f.t.Text←show next ⍝ display new generation.
⍺ ∇ next ⍝ ... and so on.
}⍵
}
⍝ Fix this function and the glider_gun as described in "Library" above
⍝ and then try:
100 life gui 30 80↑glider_gun='⍟' ⍝ glider gun on torus.
⍝ But beware: a glider gun in a torus is doomed because it inevitably shoots
⍝ itself in the back. Artillery in a finite manifold is a dangerous business.
⍝
⍝ Aficionados of the 1970s arcade game "Asteroids", which took place on a
⍝ torus, will recall that the manufacturers thoughtfully gave their canon
⍝ a range just short of the screen's circumferences.
See also: traj
Back to: contents
Back to: Dyalog APL
Trouble seeing APL font?