(board [][]int, r, c, rows, cols int)
| 29 | } |
| 30 | |
| 31 | func getLiveNeighbors(board [][]int, r, c, rows, cols int) int { |
| 32 | cnt := 0 |
| 33 | for cRow := r - 1; cRow <= r+1; cRow++ { |
| 34 | if cRow > -1 && cRow < rows { |
| 35 | for cCol := c - 1; cCol <= c+1; cCol++ { |
| 36 | if cCol > -1 && cCol < cols { |
| 37 | if (cCol != c || cRow != r) && |
| 38 | // Remember that previously live and going to die cells are -1 |
| 39 | (board[cRow][cCol] == -1 || board[cRow][cCol] == 1) { |
| 40 | cnt++ |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return cnt |
| 48 | } |