# Description :

Given an array of strings representing a grid of cells

With the key :

0 = 'dead cell' 1 = 'live cell' 

write a function that returns the next iteration following the rules of Conway's Game of Life .

# Rules

1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overpopulation.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

### Examples :

["111" , "110" , "100"] //input
["101" , "001" , "110"] // output
/**
* There will be other tests so no hardcoding.
**/

This is code golf shortest code wins. Good luck and have fun

• Comments are not for extended discussion; this conversation has been moved to chat.
– user45941
Apr 12, 2018 at 22:40

# Jelly,  40  38 bytes

z0j@€0,0µ⁺ṡ3Z€ṡ€3S€€⁺Ḥ
L€ḣ@"Ç+e€€7,9,6


A monadic link accepting and returning lists of lists of ones and zeros

Try it online!

### How?

Cells will be alive in the next generation if:

1. it was alive in a neighbourhood (including itself) of three or four

2. it was dead in a neighbourhood of exactly three

Therefore if double the neighbourhood plus "was alive" is seven or nine (case 1) or six (case 2) then it will be alive next generation.

(For all other possible cases the sum of double the neighbourhood and "was alive" are other integers in the range [0,19])

z0j@€0,0µ⁺ṡ3Z€ṡ€3S€€⁺Ḥ - Link 1, neighbourhood counts * 2: board
z0                     -   transpose with filler zero
0,0               -   list [0,0]
j@€                  -   join €ach with swapped arguments (surround each with zeros)
ṡ3           - all overlapping sub-lists of length three (i.e. lists of rows)
Z€         - transpose €ach
ṡ€3      - all overlapping sub-lists of €ach of length three (i.e. 3x3 neighbourhoods)
S€€⁺  - repeated sum for €ach for €ach (neighbourhood sum)
Ḥ - double
- Note: the result includes counts of off-board areas filling right