3
\$\begingroup\$

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:" where X represents a character.
  • Then, it says "If there are [amount] neighboring X, turn into Y." The amount is some numbers, separated by or, where X and Y 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:

The Result

(This code golf is inspired by this thingy, and of course, Conway's Game of Life.)

\$\endgroup\$
5
  • 11
    \$\begingroup\$ Can we take the input in a more structured form instead of a textual one? Otherwise it seems that this challenge can be split in two: parsing (which I don't think it's the interesting part) and computing the automaton final state \$\endgroup\$
    – matteo_c
    Mar 2 at 19:40
  • \$\begingroup\$ No sample output? \$\endgroup\$ Mar 2 at 22:05
  • 2
    \$\begingroup\$ I also suggest posting to the Sandbox to get feedback on challenges before posting to the main site. \$\endgroup\$ Mar 2 at 22:19
  • \$\begingroup\$ @SuperStormer added example, thanks! \$\endgroup\$
    – Infigon
    Mar 2 at 22:57
  • 1
    \$\begingroup\$ as plaintext, not an image \$\endgroup\$ Mar 2 at 23:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.