[Community Puzzle] Custom Game of Life


Send your feedback or ask for help here!

Created by @Edjy,validated by @thomas_lourseyre,@Alex-1 and @Fantomat75.
If you have any issues, feel free to ping them.

what is “the condition of surviving/dying?” I do not understand what you mean by that.

1 Like

It is a condition that defines whether a given cell will be alive/dead in the next turn.

For example:
001100000 - alive cell survives if it has 2 or 3 alive neighbours, otherwise dies
000100000 - dead cell is ressurected if it has 3 alive neighbours, otherwise stays dead


Assuming the top left cell is [0,0]:
Dead cells at [0,1] and [2,1] have 3 alive neighbours so they are brought back to life in next turn.
Alive cells at [1,0] and [1,2] have 1 alive neighbour so they die.
Alive cell at [1,1] has 2 alive neighbours so it stays alive.
All cells in corners are dead and have 2 alive neigbours so they stay dead.

Grid on next turn:


Hi thanks for the quick answer. I think I phrased my answer poorly… I meant how do you get from “001100000” to 2-3 alive neighbors, survives.

However, I think I just figured it out on second glance. Am I correct in saying the first digit is if 0 neighbors alive, second is if 1 neighbor is alive, third is if 2, 4th is if 3… etc. and 0 = die/stay dead, 1 = birth/survive?

1 Like

Yes, as per instructions :slight_smile:

The index within the line is the number of neighbours, 0 to 8

1s are on indexes 2 and 3 so rule applies if cell has 2 or 3 neighbours.

1 Like

This is not an “easy” puzzle imo. Maybe the final solution isn’t too large line-wise, but this requires quite a bit of thinking especially if you are new to cellular automata. This one took me about 25-30 minutes to solve and I’ve done cellular automata and even pixel physics sims before. Compare this to many of the other “easy” puzzles that take maybe 5-10 minutes to complete. Debugging these kinds of problems can also be a challenge for novices.

I would recommend bumping this up to the “medium” category at the very least.


I’m glad someone already asked what those instructions mean. For me it was completely unclear. I would suggest adding a bit more explanation in the description of the puzzle. Thanks for your effort.


I agree, I think it should be more explicit on how the rules of surviving and birth works with the list of nine 0 and 1 : (explain for example that in the rule of surviving, if the character at position 3 is a 1, it means that if a cell has 3 neighbours, it will survive).

But very good puzzle anyway !


It might be helpful for those that don’t know, in the Game of Life, all changes occur simultaneously. Forgetting this, I made changes as I came across them and obviously failed the first time.


Thanks for your post, i thought it was obvious, but it seems not.

What means first zero? Is this current cell? And then neighbors?

I will help for those who don’t get it…
Bytes are 000110000 - that means 012345678 if 0 neighbors then representation of array of bytes is 0, if You have 3 neighbors, then that place in array represent 1. And that means stay alive or born.

Hi guys,
I’m struggeling with this puzzle and i don’t know where the mistake in my logic is.
The code is working but I don’t pass the tests. When i go thourgh my code “by hand” i can’t identify any mistakes.
Does somebody has any idea?

Here is my code:

# inputs
h, w, n = [int(i) for i in input().split()]
alive = input()
dead = input()
alive = [i for i in range(9) if alive[i] == "1"]
dead = [i for i in range(9) if dead[i] == "1"]
grid = []

#create the grid
for i in range(h):
    line = input()

# count the number of alive neighbours 
def alive_neighbours(row, col):
    neighbours = [[grid[i][j] if  i >= 0 and i < len(grid) and j >= 0 and j < len(grid[0]) else "."
                for j in range(col-2, col+1)]
                    for i in range(row-2, row+1)]
    count = sum(x.count('O') for x in neighbours)
    return count if grid[row-1][col-1] == "." else count-1

# main iteration for the game
for _ in range(n):
    for i in range(1, len(grid)+1):
        for j in range(1, len(grid[0])+1):
            neighbours = alive_neighbours(i, j)
            if not neighbours in alive:
                grid[i-1][j-1] = "."
            if neighbours in dead:
                grid[i-1][j-1] = "O"

# output           
for line in grid:

From a quick look:

  • your count of alive neighbours includes the actual cell
  • you are changing the grid when iterating over cells which affects subsequent cells. The cell is supposed to be changed based on how the grid looks at the beginning of a turn.
1 Like

Agreed ! I even did not understand the problem in first 5-7 minutes

I have a problem when submitting. Basically, I can pass all tests, but when I try submitting, tests are wrong. Which is fine, because it’s clearly stated that it can be the case. My problem is that the wrong tests are different each time I submit my code with no modification.
I cannot put pictures, because I’m new, but for example, after clicking on the submit button the tests number 1, 2, 3 and 5 are wrong. After re-submitting now it’s 6 and 8 which are wrong. I tried it a dozen of times and each time is different… So I can’t really understand where my problem is and how to correct :confused:
Because everything works on the normal test I don’t know if I’m authorized to post my code here. But if it’s possible and you need it, I will.

It could be timeout issues. A more efficient code may help.

I see. It’s strange because the 9th test which is the 20x20 grid with 15 iterations (so the most demanding one) can success (and sometimes no). It’s totally random…
Maybe my success depends if the server is busy or not ? … Which is bad ^^.
I’ll try to optimize a little. If nothing works, I’ll post again. Thanks !

Yes, it may also be just a server issue :smile:
See if optimization of your code helps first!

The instructions on this puzzle are completely unclear. Oh, btw, your code doesn’t work either.