This challenge is one of the two challenges which were planned for Advent of Code Golf 2021, but didn't fit into the 25-day schedule.
Related to AoC2020 Day 24, Part 2.
Given a binary configuration on a hexagonal grid, output the next generation of Hexagonal Game of Life using AoC rules:
- A living cell survives if it has one or two living neighbors. Otherwise, it turns into a dead cell.
- A dead cell becomes alive if it has exactly two living neighbors. Otherwise, it does not change.
A hexagonal grid can be input and output in any sensible 2D or 3D representation. The input grid has a shape of a regular hexagon. You can choose how to handle the borders: either expand it by one layer, or keep the input size. You can choose the values of alive and dead cells, but they must be consistent across input and output.
You may choose the two distinct values for the alive and dead cells in the input and output, and you may use the value for "dead" or the third value for the necessary padding.
Standard code-golf rules apply. The shortest code in bytes wins.
Example I/O
An input representing the following grid
. . .
* . . *
* . * * *
* * * .
* . .
could be skewed to the right, giving
. . .
* . . *
* . * * *
* * * .
* . .
or, as a Python 2D array using 0 and 1 (with zero padding),
[[0, 0, 0, 0, 0],
[0, 1, 0, 0, 1],
[1, 0, 1, 1, 1],
[1, 1, 1, 0, 0],
[1, 0, 0, 0, 0]]
The expected output for this input, if expanding by one layer, is
. . . .
. . . . .
* * * . * *
. * . . . * .
* . . . . .
* * . . .
. . . .
or, in the same representation,
[[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1],
[0, 1, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]]
As written above, you're free to choose to not expand the borders, in which case the result would be
. . .
* * . *
* . . . *
. . . .
* . .
[[0, 0, 0, 0, 0],
[0, 1, 1, 0, 1],
[1, 0, 0, 0, 1],
[0, 0, 0, 0, 0],
[1, 0, 0, 0, 0]]
Example code is here.