Jungle of Life


Collapse Content

The goal of this challenge is to create a variant of the Game of Life you created in the previous challenge. Here are the new twists:

  • two species of life: 1 and 2.
  • continuous board - the left edge and right edge are connected, as are the top and bottom edge. In the grid below, the 1's are all 1 step away from the X:

    1 0 1 1
    1 0 1 X
    1 0 1 1
    0 0 0 0
  • custom rules for each test case are given as input (see below)

  • larger area of neighboring cells of influence, e.g. you may need to check 5 cells in each direction instead of 1.

  • output the 50th turn of the game for each case.

Input

  • The first line of input contains t, the number of test cases. t test cases follow. Each test case starts with an initial line with 5 numbers:
    • n, for the size of the grid.
    • length - the length to check in each direction for the neighboring cells of influence
    • min - cell dies if surrounding cells contain min live cells or less.
    • alive - cell becomes alive if surrounding cells contain this number (or greater) of cells of one species of life.
      For example, if alive is 4, then a cell will become a 2 if there are 4 or more 2's nearby, and it will become a 1 if there are 4 or more 1's nearby. (Assuming the total nearby alive cells is less than max, otherwise see the next bullet.)
    • max - cell always dies if surrounding cells contain max live cells or more.
  • After the initial line, n lines follow, containing the grid for a given case.

Here's the first line of input for a game very similar to the standard game of life (from the previous challenge):

20 1 1 3 4

Hover above for more info.

(The difference in this version is there are two species of life instead of one.)

Sample Input

1
20 1 1 3 4
0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Output

Output the 50th run of each case (don't include the initial input.)

02000000000000000000
02000000000000000000
02000000000000000000
00000000000000000000
00000000010000000000
00000000111000000000
00000001111100000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000001111100000000
00000000111000000000
00000000010000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
~

Challenge

Create a program to run the Jungle of Life as described above and output the 50th turn of each case.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

  • How should we break ties when there are the same number of 1s and 2s?

  • The cell stays the same if there aren't enough neighbors to overpopulate it ('kill it') or to 'give birth'. (If there are enough of both neighbors to 'give birth', the total will always be overpopulated.)

  • One piece that I missed was that I had assumed that the cell need to be dead in order to 'give birth'. That's not the case. Cells can change species even if they are already alive.

  • @brad Thanks for the advice. Hard to tell that from the directions.

  • Updated directions with example.

Contact Us