https://www.codingame.com/training/easy/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.

https://www.codingame.com/training/easy/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

```
.O.
.O.
.O.
```

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:

```
...
OOO
...
```

3 Likes

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

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

001100000

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

2 Likes

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.

12 Likes

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.

3 Likes

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 !

3 Likes

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.

2 Likes

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()
grid.append(list(line))
# 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:
print("".join(line))
```

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

Hello,

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

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

See if optimization of your code helps first!

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