A cell is 'on' in generation i+1 if in generation i if it is 'on' in generation i or has exactly 1 neighbor.
The automaton operates on a hexagonal lattice. Alternating rows produce left- and right-configurations:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 190 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
So e.g. the neighbors of cell 12 are cells 6 7 11 13 16 and 17, and those of cell 7 are cells 2 3 6 8 12 and 13. Translated to a rectangular grid:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 190 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
We can see that neighborhoods centered on even-numbered rows exclude the cells at the upper- and lower-right corners of the 3 x 3 rectangle on which they are centered, and those on odd-numbered rows exclude the cells at the upper- and lower-left.
In the Hex automaton, we compute the next generation with 'next':
next:{x|1=+/alt adj x}
The next generation of x is x or 1 = the sum of the alternating adjacencies of x.
The adjacencies - or neighbors - are computed by performing nine transformations on the current state of the universe:
adj:{(r'r@;r'l@;l'r@;l'l@;l';r';r:-1!;l:1!)@\:x}
l:1! rotate up r:-1! rotate down r' rotate right l' rotate left l'l@ rotate up, then left l'r@ rotate down, then left r'l@ rotate up, then right r'r@ rotate down, then right
The resulting 9 x n x m aligns each cell with its nine neighbors. We can see in the example below which cells must be deleted to form the seven neighbors of a cell on even- and odd-numbered rows.
Hexagonal neighbors of a cell on an even-numbered row:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1919 15 16 17 18 4 0 1 2 3 9 5 6 7 8 14 10 11 12 13 9 5 6 7 8 14 10 11 12 13 19 15 16 17 18 4 0 1 2 3 16 17 18 19 15 1 2 3 4 0 6 7 8 9 5 11 12 13 14 10 6 7 8 9 5 11 12 13 14 10 16 17 18 19 15 1 2 3 4 0 1 2 3 4 0 6 7 8 9 5 11 12 13 14 10 16 17 18 19 15 4 0 1 2 3 9 5 6 7 8 14 10 11 12 13 19 15 16 17 18 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4
Hexagonal neighbors of a cell on an odd-numbered row:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1919 15 16 17 18 4 0 1 2 3 9 5 6 7 8 14 10 11 12 13 9 5 6 7 8 14 10 11 12 13 19 15 16 17 18 4 0 1 2 3 16 17 18 19 15 1 2 3 4 0 6 7 8 9 5 11 12 13 14 10 6 7 8 9 5 11 12 13 14 10 16 17 18 19 15 1 2 3 4 0 1 2 3 4 0 6 7 8 9 5 11 12 13 14 10 16 17 18 19 15 4 0 1 2 3 9 5 6 7 8 14 10 11 12 13 19 15 16 17 18 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4
Thus, for even-numbered cells we must exclude neighbors on the left- and right-rotation arrays, and for odd-numbered cells we must exclude neighbors on the up- and down-rotation arrays.
The 'alt' function zeroes out the appropriate rows of the first four arrays:
alt:{@[x;!4;*;(::;::;~:;~:)@\:(!(^x)1)!2]}
This has the effect of excluding cells from the subsequent summation in 'next'.
This work was inspired by the J implementation of Coxe and Reiter in Vector Vol. 19 No. 3.
The code is here.
(see The Game of Life for details.)