There's a lot of questions about Conway's Game of Life, but nothing about customization (Related: 2-Player Life). Given an input, determine the result on a 100x100 grid after some iterations. The input is given as a string. For example:
Using the character #, follow the following rules:
If there are 2 or 3 neighboring nothing, turn into #.
Using nothing, follow the following rules:
If there are 3 neighboring #, turn into #.
Output the result after 100 iterations for the cells:
[Lots of cells here]
As you might be able to tell, this is Conway's Game of Life, where a cell is alive if there are three live neighbors, and a live cell with less than two or more than three neighbors dies. You may use any kind of input, but I'll be doing it like this for simplicity.
Input
- For simplicity, a character can also be the phrase "nothing."
- Each rule is separated by two newlines. Each rule starts with, "Using the character
X
, follow the following rules:" whereX
represents a character. - Then, it says "If there are
[amount]
neighboringX
, turn intoY
." The amount is some numbers, separated byor
, whereX
andY
represent characters. It may say this multiple times. - Then it says, "Output the result after
N
iterations for the cells:" Your job is to return the result after N iterations. - Then, decode the cells given. The cells are stored with a space for empty cells, and a single character for all the other characters. Newlines separate the rows.
Also, the last rule is always for nothing
, and instead starts with "Using nothing, follow the following rules:" A cell will never turn into itself. (So, for #
, "If there are 2 $, turn into #." will not happen.)
Simply render "nothing" with a space, and all other characters normally. The other characters are ASCII and not a space.
For the iterating, follow the instructions for each character. When it says "neighboring," it means the cells next to it (including diagonals).
For the borders, "wrap around" the cells. One way to think of wrapping around is to pretend that there are 8 identical grids surrounding the current one, then updating the current ones with the new neighbors. (Sorry if my explanation was weird.)
Test case (replace \n with a newline):
Using the character #, follow the following rules:
If there are 0 or 1 #, turn into $.
If there are 4 or 5 or 6 or 7 or 8 #, turn into nothing.
Using the character $, follow the following rules:
If there are 4 nothing, turn into #.
If there are 4 or 5 or 6 or 7 or 8 $, turn into #.
Using nothing, follow the following rules:
If there are 3 #, turn into #.
Output the result after 25 iterations for the cells:
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n $$$$$$$$$$ \n $$$$$$$$$$ \n # # \n # # \n $$$ $$$ $$ \n $$$ $$$ $ \n $ $$$ $$$ \n #### #### \n ## ## \n $#$#$#$#$# \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Result:
(This code golf is inspired by this thingy, and of course, Conway's Game of Life.)