*Weekend CHALLENGE Expired* : Conway's Game of Life.
write a code that given a 2D array and a number of generations, compute n timesteps of Conway's Game of Life. The rules of the game are: Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. Any live cell with more than three live neighbours dies, as if by overcrowding. Any live cell with two or three live neighbours lives on to the next generation. Any dead cell with exactly three live neighbours becomes a live cell. The universe is infinite in both the x and y dimensions and all cells are initially dead. (If there are no living cells as input, then return [[]].) note: 1 = alive cell; 0 = dead cell 0 1 0 0 c 1 1 0 0 c has 3 neighbors therefore c: if was alive stays alive at the next gen, and if c was dead turns alive at the next generation because exactly 3 neighbors. EXAMPLE: getGeneration(cells,nroGeneration); getGen([[]],3); //output itself: [[]] getGen([ [ 1, 0, 0 ], [ 0, 1, 1 ], [ 1, 1, 0 ] ], 1); //output: [[0,1,0],[1,1,1],[1,1,1]] getGen([[1,1,1],[0,1,0],[1,1,0]], 1); //output: [[0,1,0],[1,1,1],[0,0,0],[1,1,0]] HAPPY WEEKEND! 👍 note: referenced from: https://www.codewars.com/kata/conways-game-of-life-unlimited-edition DEMO, from: https://jsfiddle.net/makeschool_dion/zose7rv3/embedded/result/ One of the best answers, sponsored by JavaScript & Codewars: ANSWER: .https://code.sololearn.com/WdGZ8v3qNuq0/?ref=app Try it in other language!