{ var liveNeighborCount = 0 for yy in max(0,y-1)...min(board.count-1,y+1) { for xx in max(0,x-1)...min(board[0].count-1, x+1) { liveNeighborCount += board[yy][xx] > 0 ? 1 : 0 } } liveNeighborCount -= board[y][x] > 0 ? 1 : 0 return liveNeighborCount } func gameOfLife(_ board: inout [[Int]]) { var numNeighbors:[[Int]] = board for y in 0..<board.count { for x in 0..<board[0].count { numNeighbors[y][x] = countLiveNeighbor(x: x, y: y, board: board) } } } }